javascript - vue中自訂事件如何傳遞參數?
阿神
阿神 2017-06-28 09:28:24
0
1
934

如程式碼所示,在子元件中定義和觸發了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>
阿神
阿神

闭关修行中......

全部回覆(1)
代言

v-on:select="updSelect"

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!