vue,vuex同步数据问题 在线等 急急

<template>
    <div id="app">

        <loading showTxt="加载中,请稍后" :isShow="isShow"></loading>
        <nv-head></nv-head>
        <router-view></router-view>
        {{isShow}}
    </div>
</template>

<script>
    import nvHead from './components/header.vue';
    import loading from './components/loading.vue';

    export default {
        name      : 'app',
        data () {
            return {
                isShow: this.$store.getters.loadingState
            }
        },
        components: {
            nvHead,
            loading
        },
        handleSelect(key, keyPath) {
            console.log(key, keyPath);
        }
    }
</script>

此时我其他页面修改了this.$store.getters.loadingState 这个参数,但是这里没有双向绑定,请问怎么办
阅读 3.4k
3 个回答

在computed中获得相应的值
比如:

import { mapGetters } from 'vuex'

// 这里省略

computed: {
   ...mapGetters({
        isShow: loadingState 
    }) 
}

vuex的数据要放到computed里面做计算属性

你可以将这个数据(isShow或者loadingState)写到vuex里面,在其他组件内通过mutation来改变这个数据的值,就可以实现实时同步了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题