• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Vue3报错处理合集

武飞扬头像
哇哦Q
帮助1

目录

1、Getting a value from the `props` in root scope of `setup()` will cause the value to lose reactivity

2、vue2 升级到 vue3 router 动态授权路由 异步加载报错 TypeError Cannot read properties of undefined (reading ‘apply‘)

3、Do not access Object.prototype method 'hasOwnProperty' from target object

4、vue中使用element-ui 菜单栏(el-menu)点击双击两次才高亮的bug

5、vue2项目转换到vue3

6、Type 'string' is not assignable to type 'never'

7、类型“{}”上不存在属性“img”


这些报错是我在自己按照vue-admin-template的模板,自己改编成vue3-elementPlus-admin后台模板的时候遇到的一些报错,在这里记录下来。

1、Getting a value from the `props` in root scope of `setup()` will cause the value to lose reactivity

学新通

 添加以下注释即可

  1.  
    /* eslint-disable */
  2.  
    // eslint-disable-next-line vue/no-setup-props-destructure

学新通

2、vue2 升级到 vue3 router 动态授权路由 异步加载报错 TypeError Cannot read properties of undefined (reading ‘apply‘)

原本:

(resolve: any) => require([`@/views/${v.component}`], resolve)

改成:

() => require.ensure([], (require) => require(`@/views/${v.component}`))

3、Do not access Object.prototype method 'hasOwnProperty' from target object

原本的:

v.hasOwnProperty('items')

改成:

Object.prototype.hasOwnProperty.call(v, 'items')

4、vue中使用element-ui 菜单栏(el-menu)点击双击两次才高亮的bug

原因:default-active和index属性不一致导致的

解决方法:使用路由的name属性设置给index和default-active

5、vue2项目转换到vue3

禁用Vetur

学新通

安装插件Vue Language Features (Volar) 

学新通

6、Type 'string' is not assignable to type 'never'

上面提示的意思就是:类型“string[]”不能分配给类型“never[]”。

原因:如果ts中声明变量时没有声明类型,默认的话会是never[],而其他类型不能分配给类型never[],

Never的意思是其它类型(包括 null 和 undefined)的子类型,代表从不会出现的值。

  1.  
    const data = reactive({
  2.  
    tableData: [] as any[],
  3.  
    tableColumns: [] as any[]
  4.  
    });

7、类型“{}”上不存在属性“img”

  1.  
    const data = reactive({
  2.  
    info: {},
  3.  
    });
  4.  
    function GetFromData() {
  5.  
    data.info={img:'png'}
  6.  
    }
  7.  
     
  8.  
    console.log(data.info.img);//报错
  9.  
    console.log(data.info['img']);//不报错

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhggcbgg
系列文章
更多 icon
同类精品
更多 icon
继续加载