I am trying to set a default parameter value for a function in one of my component methods like:
methods: {
myFuntion(isAction = false) {}
}
But when debug the value of isAction I get a "MouseEvent"?
I am trying to set a default parameter value for a function in one of my component methods like:
methods: {
myFuntion(isAction = false) {}
}
But when debug the value of isAction I get a "MouseEvent"?
I found the solution. It looks like the event is also passed to the method by default. Therefore you can set a default parameter value on a method function like:
methods: {
myFuntion(event, isAction = false) {
// isAction will be false by default
// event will have the contain the event object
}
}
<button @click="myFuntion">Default Action</button>
<!-- isAction will be event -->
<button @click="myFuntion()">Default Action</button>
<!-- isAction will be false -->
<button @click="myFuntion(true)">Special Action</button>
<!-- isAction will be true -->