给组件绑定事件,该事件是自定义的事件
<div id='root'>
  <child @click='handleClick'></child>
</div>

<script>
Vue.component('child',{
  template:'<div>hello</div>'
})
var vm = new Vue({
  el:'#root',
  methods:{
    handleClick:function(){
      alert(1);
    }
  }
})
</script>
这样在组件绑定事件是无用的

 

那我就想在组件监听原生事件怎么办呢?可以,在绑定原生事件的时候告诉vue,它是原生事件
<div id='root'>
  <child @click.native='handleClick'></child>
</div>

<script>
Vue.component('child',{
  template:'<div>hello</div>'
})
var vm = new Vue({
  el:'#root',
  methods:{
    handleClick:function(){
      alert(1);
    }
  }
})
</script>
这样就行,@click.native,后面.native,告诉vue监听的是原生事件

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2021-12-13
  • 2018-04-14
  • 2022-02-07
  • 2021-06-01
  • 2022-02-07
猜你喜欢
  • 2021-08-06
  • 2022-12-23
  • 2021-10-22
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案