vue使用$emit時,父組件無法監(jiān)聽到子組件的事件實例
更新時間:2018年02月26日 14:55:44 作者:楓似
下面小編就為大家分享一篇vue使用$emit時,父組件無法監(jiān)聽到子組件的事件實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
vue使用$emit時,父組件無法監(jiān)聽到子組件的事件的原因是$emit傳入的事件名稱只能使用小寫,不能使用大寫的駝峰規(guī)則命名
<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);//無效,不能使用大寫的駝峰規(guī)則命名
}
},
})
new Vue({
el: '#counter-event-example',
data: {
total: '點擊下面的按鈕'
},
methods: {
incrementTotal: function (b) {
this.total = b;
}
}
})
</script>
以上這篇vue使用$emit時,父組件無法監(jiān)聽到子組件的事件實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
在Vue中使用deep深度選擇器修改element UI組件的樣式
這篇文章主要介紹了在Vue中使用deep深度選擇器修改element UI組件的樣式,本文分為兩種方法給大家介紹,在這小編比較推薦使用第二種使用 deep 深度選擇器,感興趣的朋友跟隨小編一起看看吧2022-12-12
Vue中router-view和component :is的區(qū)別解析
這篇文章主要介紹了Vue中router-view和component :is的區(qū)別解析,router-view用法直接填寫跳轉(zhuǎn)路由,路由組件會渲染<router-view></router-view>標簽,本文給大家介紹的非常詳細,需要的朋友可以參考下2023-10-10
解決Vue-cli3沒有vue.config.js文件夾及配置vue項目域名的問題
這篇文章主要介紹了解決Vue-cli3沒有vue.config.js文件夾及配置vue項目域名的問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12

