小编abe*_*dev的帖子

Vuex + VueJS:未定义将计算的属性传递给子级

我正在阅读有关Vue组件的文档,但是将Vuex数据用于组件属性。

从示例中可以看出,如果country_id在该data方法中运行良好。但是,当country_id计算属性从Vuex存储返回数据时,子组件的internalValue总是初始化为undefined

我究竟做错了什么?

父组件:

export default {
    computed: {
        country_id() {
            return this.$store.state.user.country_id
        }
    },
    mounted: function () {
        this.$store.dispatch('user/load');
    }
}
Run Code Online (Sandbox Code Playgroud)
export default {
    computed: {
        country_id() {
            return this.$store.state.user.country_id
        }
    },
    mounted: function () {
        this.$store.dispatch('user/load');
    }
}
Run Code Online (Sandbox Code Playgroud)

子组件:

export default {
    props: [ 'value' ],
    data: function() {
        return {
            internalValue: null,
        };
    },
    mounted: function() {
        this.internalValue = this.value;
    },
    watch: {
        'internalValue': function() …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vuex vuejs2

7
推荐指数
1
解决办法
3587
查看次数

标签 统计

javascript ×1

vue.js ×1

vuejs2 ×1

vuex ×1