vue的emit小技巧


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) }

這樣的寫法不用在父組件中寫調用方法,更簡潔


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM