vu3 控制台报错:[Vue warn]: Unhandled error during execution of component

每次按提交的报错信息:

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('登录失败')
  }
}

现在运行就没问题了

相关推荐

  1. vue3+ts require

    2023-12-17 23:42:03       59 阅读
  2. vue3+ts 引入 json-editor-vue3

    2023-12-17 23:42:03       22 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-17 23:42:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-17 23:42:03       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-17 23:42:03       87 阅读
  4. Python语言-面向对象

    2023-12-17 23:42:03       96 阅读

热门阅读

  1. C语言——谁考了第k名(编程题目)

    2023-12-17 23:42:03       59 阅读
  2. 从零开始搭建Go语言开发环境

    2023-12-17 23:42:03       63 阅读
  3. gdb print,gdb x和gdb display的使用

    2023-12-17 23:42:03       68 阅读
  4. Spring Boot注解说明

    2023-12-17 23:42:03       56 阅读
  5. 【.Net 6.0--通用帮助类--ConvertHelper】

    2023-12-17 23:42:03       48 阅读
  6. gd32F303串口接收的几种方式

    2023-12-17 23:42:03       50 阅读
  7. 深度学习之模型权重

    2023-12-17 23:42:03       70 阅读