Why is it that when using vuex, the variable under the router/ folder referenced in state is always undefined?
the directory structure is as follows:
src/router/constantRouter.js
src/store/vuex_modules/admin.js
reference code
constantRouter.js
import Home from "../views/home/index.vue"
//
import err401 from "../views/error/err401.vue"
import err404 from "../views/error/err404.vue"
import err500 from "../views/error/err500.vue"
import login from "../views/login/index.vue"
//
import main from "../views/home/main.vue"
//
import uploadList from "../views/components/uploadList.vue"
// authRule
const crm1 = [
{
path: "*",
component: err404,
hidden: true
},
{
path: "/401",
component: err401,
name: "401",
hidden: true
},
{
path: "/404",
component: err404,
name: "404",
hidden: true
},
{
path: "/500",
component: err500,
name: "500",
hidden: true
},
{
path: "/login",
component: login,
name: "",
hidden: true
},
{
path: "/",
component: Home,
redirect: "/readme",
name: "",
hidden: true
},
{
path: "/readme",
component: Home,
redirect: "/readme/main",
icon: "shouye",
name: "",
noDropdown: true,
children: [
{
path: "main",
component: main
}
]
},
{
path: "/components",
redirect: "/components/uploadList",
component: Home,
name: "components",
icon: "tongyong",
children: [
{
path: "uploadList",
name: "",
component: uploadList
}
]
}
]
export default crm1
export const tname = "jerry"
admin.js
import { userInfo, login, logout } from "../../api/login"
import * as types from "../mutation-types"
import crm1, {tname} from "../../router/constantRouter"
import {
getToken,
setToken,
removeToken,
getAdminId,
setAdminId,
removeAdminId
} from "../../util/authUtils"
import { Message } from "element-ui"
// initial state
const state = {
adminId: getAdminId(), // id
userName: "admin", //
avatar: "https://wx.qlogo.cn/mmopen/", //
token: getToken(), // token
authRules: [], //
routers: crm1 //
}
console.log("debug4")
console.log(state)
console.log(state.routers)
console.log(tname)
related screenshots