refactor:add keep-alive && component add name

This commit is contained in:
Pan
2017-10-31 10:49:24 +08:00
parent a932272b8f
commit 1ae31fdd45
28 changed files with 147 additions and 63 deletions

View File

@@ -5,7 +5,8 @@ const app = {
sidebar: {
opened: !+Cookies.get('sidebarStatus')
},
visitedViews: []
visitedViews: [],
cachedViews: []
},
mutations: {
TOGGLE_SIDEBAR: state => {
@@ -18,17 +19,28 @@ const app = {
},
ADD_VISITED_VIEWS: (state, view) => {
if (state.visitedViews.some(v => v.path === view.path)) return
state.visitedViews.push({ name: view.name, path: view.path })
state.visitedViews.push({
name: view.name,
path: view.path
})
if (!view.meta.noCache) {
state.cachedViews.push(view.name)
}
},
DEL_VISITED_VIEWS: (state, view) => {
let index
for (const [i, v] of state.visitedViews.entries()) {
if (v.path === view.path) {
index = i
state.visitedViews.splice(i, 1)
break
}
}
for (const i of state.cachedViews) {
if (i === view.name) {
const index = state.cachedViews.indexOf(i)
state.cachedViews.splice(index, 1)
break
}
}
state.visitedViews.splice(index, 1)
}
},
actions: {