私はこのdocumentation on Vue componentsを通して読んでいますが、コンポーネントのプロパティにはVuexデータを使用しています。Vuex + VueJS:計算されたプロパティを子に渡すことは定義されていません
この例では、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');
}
}
<template>
<child v-model="country_id"></child>
</template>
子コンポーネント:
export default {
props: [ 'value' ],
data: function() {
return {
internalValue: null,
};
},
mounted: function() {
this.internalValue = this.value;
},
watch: {
'internalValue': function() {
this.$emit('input', this.internalValue);
}
}
};
<template>
<p>Value:{{value}}</p>
<p>InternalValue:{{internalValue}}</p>
</template>