每次按提交的报错信息:
runtime-core.esm-bundler.js:41 [Vue warn]: Unhandled error during execution of component event handler at <ElButton onClick=fn<login> class="button" type="primary" ... >
代码:
const login = async () => {await form.value.validate()const res = await userLoginService(formModel.value)userStore.setToken(res.data.token)ElMessage.success('登录成功')router.push('/')
}
解决方法:
用
try/catch
抛出错误
const login = async () => {try {await form.value.validate()const res = await userLoginService(formModel.value)userStore.setToken(res.data.token)ElMessage.success('登录成功')router.push('/')} catch (error) {ElMessage.error('登录失败')}
}
现在运行就没问题了