1***@163.com
1***@163.com
  • 发布:2025-07-02 18:45
  • 更新:2025-07-02 19:07
  • 阅读:56

【报Bug】@vue/shared 3.4.21 以上版本 Cannot assign to read only property '\_' of object '#<Object>'

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 11

HBuilderX类型: 正式

HBuilderX版本号: 4.45

手机系统: Android

手机系统版本号: Android 14

手机厂商: 小米

手机机型: Redmi K60

页面类型: vue

vue版本: vue3

打包方式: 离线

项目创建方式: HBuilderX

示例代码:

异常代码

const initSlots = (instance, children) => {  
  if (instance.vnode.shapeFlag & 32) {  
    const type = children._;  
    if (type) {  
      instance.slots = toRaw(children);  
      shared.def(children, "_", type);  
    } else {  
      normalizeObjectSlots(  
        children,  
        instance.slots = {});  
    }  
  } else {  
    instance.slots = {};  
    if (children) {  
      normalizeVNodeSlots(instance, children);  
    }  
  }  
  shared.def(instance.slots, InternalObjectKey, 1);  
};

uni-app-vue 正常代码

// uni-app-vue 中加了一个参数,就是正常的  
shared.def(children, "_", type, true); 

操作步骤:

@dcloudio/uni-h5-vue 3.0.0-4040520250104002 + vue 3.5.13

预期结果:

正常

实际结果:

启动报错 Cannot assign to read only property '_' of object '#<Object>'

bug描述:

使用 vue3.4.21 以上的版本时,报错 Cannot assign to read only property '_' of object '#<Object>',原因来自 @dcloudio/uni-h5-vue 和 @vue/shared

2025-07-02 18:45 负责人:无 分享
已邀请:
DCloud_UNI_JBB

DCloud_UNI_JBB

你是用到了 @vue/shared 下面的方法引起的报错,还是uniapp内部的代码引起的报错?

  • DCloud_UNI_JBB

    使用vue 3.4.21有问题吗?

    2025-07-02 20:08

  • 1***@163.com (作者)

    回复 DCloud_UNI_JBB: @dcloudio/uni-h5-vue 这个包的问题,是uniapp自己重写的吧,或者是不是@dcloudio/uni-h5-vue指定了低版本

    2025-07-02 20:48

  • 1***@163.com (作者)

    回复 DCloud_UNI_JBB: 3.4.21没问题

    2025-07-03 13:47

  • DCloud_UNI_JBB

    回复 1***@163.com: vue版本最好和uniapp内部依赖的版本保持一致

    2025-07-03 14:06

要回复问题请先登录注册