Home > Net >  Uncaught SyntaxError: Function statements require a function name
Uncaught SyntaxError: Function statements require a function name

Time:07-13

I'm trying to use an onClick in a v-btn that calls a function that will perform an action, when I click the browser console returns the following error:

Uncaught SyntaxError: Function statements require a function name

I'm passing the onclick like this :

:onClick="viewForm"

Using the function call as below, the alert I put to perform tests is generated, but without clicking on v-btn, when clicking on v-btn the error is generated :

Uncaught SyntaxError: Unexpected identifier

:onClick="viewForm()"

Does anyone have an idea what the error could be ? or if some part of my code doesn't make sense.

Every help is welcome :)

CodePudding user response:

To bind a click event on any element in Vue. You have to use either @click or v-on:click. You can have a look into this official documentation of Event Handling to understand it in better way.

Hence, change it to v-on:click="viewForm" from :onClick="viewForm" will work without any errors.

CodePudding user response:

apparently using @click is working

  • Related