简体   繁体   中英

@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.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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