595
595
  • 发布:2024-03-13 14:39
  • 更新:2024-03-13 14:39
  • 阅读:182

移动端中无法拿到vuex中的对象

分类:HBuilderX

这是我的store/index.js

import Vue from "vue"  
import Vuex from "vuex"  

Vue.use(Vuex);  

const store = new Vuex.Store({  
    state: {  
        viewer: '111111111111' // 在这里定义你的viewer  
    },  
    mutations: {  
        setViewer(state, viewer) {  
            console.log('---------------setViewer----------------');  
            state.viewer = viewer;  
            console.log('--------vuex中的viewer为:' + state.viewer + '-----------');  
        }  
    },  
    getters: {  
        getViewer(state) {  
            console.log('---------------getViewer----------------');  
            console.log('--------vuex中的viewer为:' + state.viewer + '-----------');  
            return state.viewer;  
        }  
    },  
})  

export default store

我在一个组件中通过store.commit('setViewer', this.viewer);将初始化的viewer传至vuex中,在别的组件中使用mapGetters取值,在浏览器中进行测试打印出来的为:(使用mapState在浏览器也能实现,移动端还是不行)

14:33:36.598 App Launch at App.vue:4
14:33:36.600 App Show at App.vue:7
14:33:38.093 ---------------setViewer---------------- at store/index.js:12
14:33:38.095 --------vuex中的viewer为:[object Object]----------- at store/index.js:14
14:33:38.103 Cesium的版本号:1.83 at components/InitCesium.vue:79
14:33:40.950 拿到的viewerundefined at components/BasicFunction.vue:192
14:33:40.951 ---------------getViewer---------------- at store/index.js:19
14:33:40.958 --------vuex中的viewer为:[object Object]----------- at store/index.js:20
14:33:40.962 vuex中的viewer[object Object] at components/BasicFunction.vue:193

在移动端打印为:
14:33:26.101 App Launch at App.vue:4
14:33:26.107 App Show at App.vue:7
14:33:35.126 ---------------setViewer---------------- at store/index.js:12 at app-view.js:1600
14:33:35.129 --------vuex中的viewer为:[object Object]----------- at store/index.js:14 at app-view.js:1600
14:33:35.129 Cesium的版本号:1.83 at components/InitCesium.vue:79 at app-view.js:1600
14:36:46.591 拿到的viewerundefined at components/BasicFunction.vue:192
14:36:46.603 ---------------getViewer---------------- at store/index.js:19
14:36:46.603 --------vuex中的viewer为:111111111111----------- at store/index.js:20
14:36:46.604 vuex中的viewer111111111111 at components/BasicFunction.vue:193

可以看到移动端上已经成功将viewer传至vuex,但是取值取到的还是没更新的viewer,请问各位大佬应该如何解决这个问题

2024-03-13 14:39 负责人:无 分享
已邀请:

要回复问题请先登录注册