3👍
✅
- Vue component’s
data
must be a function, not an arrow function since an arrow function doesn’t have athis
. From Vue.js docs:
Don’t use arrow functions on an options property or callback, such as
created: () => console.log(this.a)
orvm.$watch('a', newValue => this.myMethod())
. Since an arrow function doesn’t have athis
, this
will be treated as any other variable and lexically looked up through
parent scopes until found, often resulting in errors such asUncaught TypeError: Cannot read property of undefined
orUncaught TypeError: this.myMethod is not a function
.
- You are referencing
pw1
andpw2
which are not defined indata
.
Here is Codepen
Source:stackexchange.com