搜尋

首頁  >  問答  >  主體

javascript - vue中自訂事件如何傳遞參數?

如程式碼所示,在子元件中定義和觸發了select方法並將type參數傳入,在父元件中引入子元件,並監聽select事件

結果報錯:「Property or method "type" is not defined on the instance but referenced during render.」 是我傳遞參數的方法不對嗎?

//子组件
<button type="button" name="button" class="all" v-bind:class="{'active':selectType===2}" 
v-on:click="select(2,$event)">
      {{desc.all}}
      <span class="count">{{ratings.length}}</span>
</button>


<script type="text/ecmascript-6">
    methods:{
      select:function (type,event) {
        if (!event._constructed){
          return;
        }
        this.$emit('select',type)
      }
</script>
//父组件
<rating-select v-bind="{ratings:food.ratings,selectType:selectType,onlyContent:onlyContent}"
  v-on:select="updSelect(type)" v-on:toggleContent="toggleContent"
  class="rating-select">
</rating-select>

<script>
    updSelect:function (type) {
        this.selectType = type
      }
</script>
阿神阿神2775 天前989

全部回覆(1)我來回復

  • 代言

    代言2017-06-28 09:30:24

    v-on:select="updSelect"

    回覆
    0
  • 取消回覆