您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

入口文件中,怎么才能及时的拿到vuex中的数据

入口文件中,怎么才能及时的拿到vuex中的数据

项目入口文件
app.vue

<script>
.....
create() {
          const that = this;
          that.$store.dispatch('Getsiteinfoactions');
          console.log(that.$store.state.siteinfo);
...........

在VUEX中Getsiteinfoactions是调用接口给siteinfo进行赋值

actions:{
        Getsiteinfoactions(context){
            axios.get('/api/wapinfo/index').then(response => {
                context.commit("Getsiteinfomutations",response.data.data);
            })
        },

axios是一个异步,导致不能及时的把请求到的值赋给siteinfo

有什么办法可以解决这个问题吗?

vue.js 2022/2/18 19:29:30 有565人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶