当前位置: 移动技术网 > IT编程>脚本编程>vue.js > vue使用$emit时,父组件无法监听到子组件的事件实例

vue使用$emit时,父组件无法监听到子组件的事件实例

2018年04月20日  | 移动技术网IT编程  | 我要评论

魔藤碎片,affection香水,夫妻成长日记漫画版

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时,父组件无法监听到子组件的事件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网