在學習vue自定義事件的.sync修飾符實現改變數值時發現一個問題如下
由於props的大小寫命名:fatherNum
,對應不同的$emit()會有不同的效果,具體如下:
使用.sync修飾符,即
// this.$emit('update:father-num',100); //無效 this.$emit('update:fatherNum',100); //有效 //...... <father v-bind:father-num.sync="test"></father>
與不使用.sync,即
this.$emit('update:father-num',100); //有效 //this.$emit('update:fatherNum',100); // 無效 //...... <father v-bind:father-num="test" v-on:update:father-num="test=$event" ></father>