5👍
✅
Don’t use arrow functions to define your methods. At execution this
will be wrong, because arrow functions preserve the this
(also called context) from the time of their definition. Methods are defined as part of the component definition process, so the component is not the context when the method is being defined.
An ordinary function
definition will determine context based on how it is called, so component.method()
will have component
as its context, which is what you want.
If your method doesn’t reference this
, you can use arrow functions, but I recommend against it, because there will come times that you update the definition, use this
, and it will bite you.
1👍
try this:
data() {
return {
show: false
}
},
This is how I use my data for my components.
Source:stackexchange.com