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. docker绑定了nginx端口 外部访问不到2. docker容器呢SSH为什么连不通呢?3. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?4. docker安装后出现Cannot connect to the Docker daemon.5. docker镜像push报错6. angular.js使用$resource服务把数据存入mongodb的问题。7. dockerfile - 我用docker build的时候出现下边问题 麻烦帮我看一下8. docker gitlab 如何git clone?9. 我在centos容器里安装docker,也就是在容器里安装容器,报错了?10. 关于docker下的nginx压力测试