search

Home  >  Q&A  >  body text

javascript - How to pass parameters to custom events in vue?

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>
阿神阿神2705 days ago966

reply all(1)I'll reply

  • 代言

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

    v-on:select="updSelect"

    reply
    0
  • Cancelreply