【Vue3】报错处理合集

目录

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

 添加以下注释即可

/* eslint-disable */
// 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)的子类型,代表从不会出现的值。

const data = reactive({
   tableData: [] as any[],
   tableColumns: [] as any[]
});

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

const data = reactive({
   info: {}, 
});
function GetFromData() {
   data.info={img:'png'}
}

console.log(data.info.img);//报错
console.log(data.info['img']);//不报错

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值