简体   繁体   English

@click 事件在 vue 组件中不起作用

[英]@click event not working in vue component

I've vue component and in it I wrote a function: when button is clicked likes get + 1 but it never works, I tried to write it inside component like this `@click="this.likes++' but not working, after that I created a method but it also not working. any help?我有 vue 组件,在其中我写了一个 function: 当按钮被点击时likes get + 1 但它永远不会工作,我试图将它写在像这样的组件内 `@click="this.likes++' 但不工作,之后我创建了一个方法,但它也不起作用。有什么帮助吗?

Vue.component('task-list',{
  template: '<div><button @click="ggg">click me</button>{{ likes }}</div>',
  data(){
    return{
      likes:1
    }
  },
  methods:{
    ggg(){
      this.likes++
    }
  }
});

Are you sure you are doing this properly?你确定你这样做正确吗? I have created a codesandbox using your code snippet and it works perfectly.我使用您的代码片段创建了一个代码,它运行良好。

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

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