[Vuejs]-VUE JS – Some of my methods are being called without me calling them

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

https://v2.vuejs.org/v2/guide/events.html

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 () {
      ...
    }

Leave a comment