Javascript 如何从计算属性设置子组件中的数据
我目前正在使用Javascript 如何从计算属性设置子组件中的数据,javascript,vue.js,nuxt.js,vuex,vue-multiselect,Javascript,Vue.js,Nuxt.js,Vuex,Vue Multiselect,我目前正在使用vue multiselect构建一个过滤器。一切正常,但我面临的唯一问题是,在重新加载页面时,标签(v-model)是空的 原因当然是,v-modelselectedOption在页面重载时为空,因为父组件的道具是计算属性 为了获得最好的可读性,我将剪切大部分代码 父组件(ProductList.vue): <template> <section> <ProductListFilter v-bind:currentProductType=
vue multiselect
构建一个过滤器。一切正常,但我面临的唯一问题是,在重新加载页面时,标签(v-model)是空的
原因当然是,v-modelselectedOption
在页面重载时为空,因为父组件的道具是计算属性
为了获得最好的可读性,我将剪切大部分代码
父组件(ProductList.vue):
<template>
<section>
<ProductListFilter v-bind:currentProductType="currentProductType"
</section>
</template>
<script>
import {mapGetters} from 'vuex';
export default {
computed: {
...mapGetters({
currentProductType: 'shop/productTypes/currentProductType',
}),
},
mounted() {
this.$store.dispatch('shop/productTypes/setCurrentProductType', this.productType);
},
}
</script>
只要currentProductType
发生更改,您就可以添加watch
属性来更新selectedProductType
。在子组件中:
watch: {
currentProductType(val) {
this.selectedProductType = val;
}
}
watch: {
currentProductType(val) {
this.selectedProductType = val;
}
}