1//In your component (here TaskTemplate.vue)
2methods: {
3 add() {
4 this.$emit('add-counter', this.taskId);
5 }
6}
7
8//In App.vue
9<task-template
10 :task-name="task.name"
11 :task-id="task.id"
12 :task-counter="task.counter"
13 @add-counter="addTaskCounter"
14 >
15</task-template>
16
17//...
18data() {
19 return {
20 task: {
21 id: 0,
22 name: 'Empty been',
23 counter: '2'
24 }
25 }
26}
27
28methods: {
29 addTaskCounter(taskId) {
30 const identifiedTask = this.tasks.find((task) => task.id === taskId);
31
32 identifiedTask.counter += 1;
33 }
34}