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. python - 求一个在def中可以实现调用本def满足特定条件continue效果的方法(标题说不太清楚,请见题内描述)2. mysql - SQL操作时间的函数?3. MYSQL新建用户设置可以远程访问的问题4. javascript - 用表单提交两个时间段请求后台返回对应数据时出现的一些问题!5. angular.js - angularjs的自定义过滤器如何给文字加颜色?6. java - mybatis怎么实现在数据库中有就修改,没有就添加7. javascript - ionic run android报错8. node.js - nodejs和前端JavaScript 字符串处理结果不一样是什么原因?9. 正则表达式 - python pandas的sep参数问题10. docker内创建jenkins访问另一个容器下的服务器问题
