0👍
✅
To avoid the function to be autoexecuted, you need to provide the onclick method with the function declaration. Try the code below. I don’t use Vue, but it works in React. Javascript anyway.
:onclick="() => addProduct()"
3👍
You have the wrong syntax
:onclick="addProduct()"
:onclick
should be @click
or v-on:click
0👍
Correct syntax for click event in vue
full syntax
<a v-on:click="addProduct"></a>
shorthand syntax
<a @click="addProduct"></a>
Then call method addProduct
addProduct: function () {
...
}
Source:stackexchange.com