Error in v-on handler: “TypeError: this is not a function“
Error in v-on handler: "TypeError: this is not a function"提示:这里描述项目中遇到的问题:在进行简单登录跳转的测试中,出现Error in v-on handler: "TypeError: this is not a function"的错误async UserLogin() {try {//登录成功const {phone, passw
·
Error in v-on handler: “TypeError: this is not a function”
在进行简单登录跳转的测试中,出现Error in v-on handler: "TypeError: this is not a function"的错误
async UserLogin() {
try {
//登录成功
const {phone, password} = this
phone && password && await this.$store.dispatch('UserLogin', {phone, password})
//跳转到home首页
this.$router.push('/home');
} catch (error) {
alert(error.message);
}
}
原因:
在 const {phone, password} = this 代码后面没有加上分号,导致代码解析的时候误认为该行代码没有结束,this指向不一致
解决方案:
只需要在后面加上分号即可
async UserLogin() {
try {
//登录成功
const {phone, password} = this;
phone && password && await this.$store.dispatch('UserLogin', {phone, password});
//跳转到home首页
this.$router.push('/home');
} catch (error) {
alert(error.message);
}
}
更多推荐
已为社区贡献3条内容
所有评论(0)