feat: module state declaration as function, 详见vuex官方github:eb33ed6fbe

This commit is contained in:
chuzhixin 2020-11-29 00:10:07 +08:00
parent fd0effe803
commit 8bea3fbe1c
5 changed files with 12 additions and 9 deletions

View File

@ -1,8 +1,8 @@
const state = {
const state = () => ({
admin: false,
role: [],
ability: [],
}
})
const getters = {
admin: (state) => state.admin,
role: (state) => state.role,

View File

@ -6,7 +6,10 @@ import { asyncRoutes, constantRoutes } from '@/router'
import { getRouterList } from '@/api/router'
import { convertRouter, filterRoutes } from '@/utils/routes'
const state = { routes: [], partialRoutes: [] }
const state = () => ({
routes: [],
partialRoutes: [],
})
const getters = {
routes: (state) => state.routes,
partialRoutes: (state) => state.partialRoutes,

View File

@ -38,7 +38,7 @@ const toggleBoolean = (key) => {
return typeof theme[key] !== 'undefined' ? theme[key] : key
}
const state = {
const state = () => ({
logo,
title,
collapse,
@ -55,7 +55,7 @@ const state = {
showTagsBar: toggleBoolean(showTagsBar),
showNotice: toggleBoolean(showNotice),
showFullScreen: toggleBoolean(showFullScreen),
}
})
const getters = {
collapse: (state) => state.collapse,
device: (state) => state.device,

View File

@ -3,9 +3,9 @@
* @description tagsBar多标签页逻辑前期借鉴了很多开源项目发现都有个共同的特点很繁琐并不符合框架设计的初衷后来在github用户cyea的启发下完成了重构请勿修改
*/
const state = {
const state = () => ({
visitedRoutes: [],
}
})
const getters = {
visitedRoutes: (state) => state.visitedRoutes,
}

View File

@ -11,11 +11,11 @@ import {
import { title, tokenName } from '@/config'
import { message, notification } from 'ant-design-vue'
const state = {
const state = () => ({
accessToken: getAccessToken(),
username: '',
avatar: '',
}
})
const getters = {
accessToken: (state) => state.accessToken,
username: (state) => state.username,