javascript - vue中自定义事件如何传递参数?
阿神
阿神 2017-06-28 09:28:24
0
1
932

如代码所示,在子组件中定义和触发了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学习者快速成长!