javascript - vue中自定义事件如何传递参数?
问题描述
如代码所示,在子组件中定义和触发了select方法并将type参数传入,在父组件中引入子组件,并监听select事件
结果报错:“Property or method 'type' is not defined on the instance but referenced during render.” 是我传递参数的方法不对吗?
//子组件<button type='button' name='button' v-bind: 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'
相关文章:
1. PHP中的$this代表当前的类还是方法?2. html - 关于css选择器的问题3. python - 怎样在linux下开发flask web应用时查看代码出错(traceback)的地方。4. 如何解决tp6在zend中无代码提示5. javascript - 请问这段 el && fn.call(el, e, el)代码这么写什么意思?6. javascript - chart.js如何修改某个指定bar的颜色7. javascript - JS 里面的 delete object.key 到底删除了什么?8. css - 这些字体是怎么弄的?9. pdo_mysql 值自增写法10. python - requests post问题

网公网安备