Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript VUE(Quasar)如何在无需刷新的情况下访问本地存储数据_Javascript_Vue.js_Local Storage_Quasar Framework - Fatal编程技术网

Javascript VUE(Quasar)如何在无需刷新的情况下访问本地存储数据

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')) 我得到

我有一个带有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,例如

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')
  }
]