1、在vue中正常來說父子組件傳值一般用props屬性單向傳值,發現有更簡潔的方式,就記錄一下
2、原理:利用this.$emit("update:xx",value)和xx.sync
3、實現:
在父組件中
<component v-for="(item, index) in formItemList" v-bind:is="item.formItemType + 'Dynamic'" :key="index" :formItemList="item" :tabFormCode="tabFormCode" :currentProductCode="currentProductCode" :defaultValue="item.defaultValue || ''" :inputValue.sync="item.inputValue" :groups.sync="item.groups" :ref="item.formItemType + 'Ref'" ></component>
在子組件中
setGroups() {
this.$emit('update:groups', this.groupingArr) }
這樣的寫法不用在父組件中寫調用方法,更簡潔
