javascript - How to pass parameters to custom events in vue?
阿神
阿神 2017-06-28 09:28:24
0
1
931

As shown in the code, the select method is defined and triggered in the child component and the type parameter is passed in, the child component is introduced in the parent component, and the select event is listened to

The result is an error: "Property or method "type" is not defined on the instance but referenced during render." Is the way I pass parameters wrong?

//子组件
<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>
阿神
阿神

闭关修行中......

reply all(1)
代言

v-on:select="updSelect"

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!