简体   繁体   English

当我点击屏幕时,该函数被调用两次

[英]When I tap the screen, the function is called two times

When I tap the element, the callback function is called two times.当我点击元素时,回调函数被调用了两次。

I did try with a click event and there are no problems我确实尝试了点击事件,没有问题

    <template>
    <div>
      <div v-on:click="tap()">Click</div>
      <a v-hammer:tap="tap">Tap</a>
    </div>
    </template>

    <script>
    export default{
      name: 'say',
      beforeUpdate(){
        console.log('beforeUpdate')
      },
      updated(){
        console.log('updated')
      },
      methods: {
        tap(){
          console.log('Say',Date())
        }
      }
    }
    </script>

I expect the callback function is called once我希望回调函数被调用一次

您应该使用@click.native.prevent来避免传播,就像文档解释的那样: https ://v2.vuejs.org/v2/guide/events.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM