我正在阅读有关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)