Javascript VUE(Quasar)如何在无需刷新的情况下访问本地存储数据
我有一个带有layouts/MainLayout.vue和pages/Index.vue的标准Quasar CLI项目。这是我在Quasar CLI创建过程之后更改的仅有的两个文件 在MainLayout.vue中,我将一些数据存储在localStorage中,例如。 此.q.localStorage.set('curroumid',0) 在Index.vue中,当我尝试获取此数据时,例如。 var s=this.$q.localStorage.getItem('curroumid')) 我得到空值作为响应 如果我尝试在mounted()中获取此数据(并且我已经在所有其他生命周期挂钩中进行了尝试),我将再次得到null,例如Javascript VUE(Quasar)如何在无需刷新的情况下访问本地存储数据,javascript,vue.js,local-storage,quasar-framework,Javascript,Vue.js,Local Storage,Quasar Framework,我有一个带有layouts/MainLayout.vue和pages/Index.vue的标准Quasar CLI项目。这是我在Quasar CLI创建过程之后更改的仅有的两个文件 在MainLayout.vue中,我将一些数据存储在localStorage中,例如。 此.q.localStorage.set('curroumid',0) 在Index.vue中,当我尝试获取此数据时,例如。 var s=this.$q.localStorage.getItem('curroumid')) 我得到
if (this.$q.localStorage.has('curriculumId')) {
console.log('mounted - success')
} else {
console.log('mounted - failed')
}
控制台
挂载-失败
但是,当我点击刷新时,我的所有数据都可用
My routes.js是系统创建的
const routes = [
{
path: '/',
component: () => import('layouts/MainLayout.vue'),
children: [
{ path: '', component: () => import('pages/Index.vue') }
]
},
// Always leave this as last one,
// but you can also remove it
{
path: '*', component: () => import('pages/Error404.vue')
}
]