Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

main.js中访问vuex的问题

main.js

import router from './router'
import store from './stores.js'
......

Vue.directive('permission', {
  inserted: function (el,{value}) {
    console.log(store.state.name)
  }
})

new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app')

stores这个文件里面有请求接口赋值到state.name上面,在下面注册了一个全局指令

问题:

我在浏览器新打开一个含有这个全局指令的页面时,store的请求还没回来,导致name这个属性拿不到,请问有什么办法


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

使用路由守卫等待store接口数据返回,阻塞页面渲染


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...