vue使用$emit时,父组件无法监听到子组件的事件实例
更新时间:2018年02月26日 14:55:44 作者:枫似
下面小编就为大家分享一篇vue使用$emit时,父组件无法监听到子组件的事件实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
vue使用$emit时,父组件无法监听到子组件的事件的原因是$emit传入的事件名称只能使用小写,不能使用大写的驼峰规则命名
<div id="counter-event-example">
<p>{{ total }}</p>
<button-counter v-on:ee="incrementTotal"></button-counter>
<button-counter v-on:eEvent="incrementTotal"></button-counter>
<child ref="cmpSelect" v-on:ee="incrementTotal" option-api-url="/api/admin/cms/cmsCategory/getOptions.do"></child>
</div>
<script>
Vue.component('button-counter', {
template: '<button v-on:click="increment">{{ counter }}</button>',
data: function () {
return {
counter: 0
}
},
methods: {
increment: function () {
this.counter += 1
this.$emit('ee', this.counter);//有效
this.$emit('eEvent', this.counter);//无效,不能使用大写的驼峰规则命名
}
},
})
new Vue({
el: '#counter-event-example',
data: {
total: '点击下面的按钮'
},
methods: {
incrementTotal: function (b) {
this.total = b;
}
}
})
</script>
以上这篇vue使用$emit时,父组件无法监听到子组件的事件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
在Vue中使用deep深度选择器修改element UI组件的样式
这篇文章主要介绍了在Vue中使用deep深度选择器修改element UI组件的样式,本文分为两种方法给大家介绍,在这小编比较推荐使用第二种使用 deep 深度选择器,感兴趣的朋友跟随小编一起看看吧2022-12-12
Vue中router-view和component :is的区别解析
这篇文章主要介绍了Vue中router-view和component :is的区别解析,router-view用法直接填写跳转路由,路由组件会渲染<router-view></router-view>标签,本文给大家介绍的非常详细,需要的朋友可以参考下2023-10-10
解决Vue-cli3没有vue.config.js文件夹及配置vue项目域名的问题
这篇文章主要介绍了解决Vue-cli3没有vue.config.js文件夹及配置vue项目域名的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-12-12


最新评论