1. 程式人生 > >Vue .sync修飾符與$emit(update:xxx)寫法問題

Vue .sync修飾符與$emit(update:xxx)寫法問題

小寫 由於 fat 一個 使用 pro bin pan ops

在學習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>

Vue .sync修飾符與$emit(update:xxx)寫法問題