jacky_ruin
jacky_ruin
  • 发布:2026-04-21 16:05
  • 更新:2026-04-21 16:05
  • 阅读:32

【报Bug】Uncaught TypeError: Cannot read property '$' of undefined at uni-app-view.umd.js:7

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 5.07

手机系统: Android

手机系统版本号: Android 16

手机厂商: 小米

手机机型: 小米13

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:
// 监听新增出库订单事件,避免整页刷新带来的白屏  
            uni.$on('retraceOutOrderAddSuccess', this.insertOutOrderToList);  

/**  
             * 新增出库订单后插入到列表首位  
             * @param {Object} newOrder 新增出库订单对象  
             */  
            insertOutOrderToList(newOrder) {  
                // 避免重复插入:如果列表中已有同 id 的记录,则先移除旧的  
                if (newOrder && newOrder.id) {  
                    const idx = this.outList.findIndex(item => item.id === newOrder.id);  
                    if (idx !== -1) {  
                        this.outList.splice(idx, 1);  
                    }  
                }  
                console.log(newOrder)  
                this.outList.unshift(newOrder);  
                console.log(this.outList);  
                // 如果列表不为空,确保显示列表而不是空状态  
                if (this.outList.length > 0) {  
                    this.showInfo = true;  
                }  
            },

操作步骤:

新增一个数据,通过监听器,自动加入到已有的订单列表中

预期结果:

控制台不报错

实际结果:

控制台报错

bug描述:

新建一个订单,新建成功后,会自动调用监听方法,把本地提交的数据插入到订单列表中,
业务执行代码:

/**  
             * 新增出库订单后插入到列表首位  
             * @param {Object} newOrder 新增出库订单对象  
             */  
            insertOutOrderToList(newOrder) {  
                // 避免重复插入:如果列表中已有同 id 的记录,则先移除旧的  
                if (newOrder && newOrder.id) {  
                    const idx = this.outList.findIndex(item => item.id === newOrder.id);  
                    if (idx !== -1) {  
                        this.outList.splice(idx, 1);  
                    }  
                }  
                console.log(newOrder)  
                this.outList.unshift(newOrder);  
                console.log(this.outList);  
                // 如果列表不为空,确保显示列表而不是空状态  
                if (this.outList.length > 0) {  
                    this.showInfo = true;  
                }  
            },

执行this.outList.unshift(newOrder);这句就会报错:Uncaught TypeError: Cannot read property '$' of undefined at uni-app-view.umd.js:7
只是控制台报错,不影响操作

2026-04-21 16:05 负责人:无 分享
已邀请:

要回复问题请先登录注册