错误一:TypeError: Cannot read properties of undefined (reading 'replace')

错误二:[Vue warn]: inject() can only be used inside setup() or functional conponents.

解释:当我们使用内置 use开头的钩子函数时,不能进行嵌套去拿实例。如:

const loginOut = async () => {
 
  // 嵌套在函数内,会提示警告信息
  const router = useRouter()

  router.replace('/login')

}

解决:必须在 setup函数 第一层调用。

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐