vuex5大组件
action:定义状态对象
mutation:修改状态
action:类似于mutation,但提交的是mutation,而不是直接修改状态
getter:action的附属,获取方法,对象等
Module:模块,将store分割为多个模块
设置值
定义SET_SIDEBAR_ROUTERS,注意,在下面代码里找SET_SIDEBAR_ROUTERS
import {
login, logout, getInfo } from '@/api/login'
import {
getToken, setToken, removeToken } from '@/utils/auth'
const user = {
state: {
token: getToken(),
name: '',
avatar: '',
roles: [],
permissions: [],
level:'',
orgCode:'',
districtCode:'',
cityCode:'',
nickName:''
},
mutations: {
SET_TOKEN: (state, token) => {
state.token = token
},
SET_NAME: (state, name) => {
state.name = name
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar
},
SET_ROLES: (state, roles) => {
state.roles = roles
},
SET_PERMISSIONS: (state, permissions) => {
state.permissions = permissions
},
SET_LEVEL: (state, level) => {
state.level = level
},
SET_ORG_CODE: (state, orgCode) => {
state