水痕qaq
水痕qaq
  • 发布:2022-03-31 11:09
  • 更新:2024-02-01 12:10
  • 阅读:551

【报Bug】APP无法获取main.js中自己添加的数组原型上的方法

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: wini10专业版

HBuilderX类型: 正式

HBuilderX版本号: 3.4.3

手机系统: Android

手机系统版本号: Android 8.0

手机厂商: 小米

手机机型: k30pro

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

main.js

        Vue.config.productionTip = false  
        Array.prototype.remove || (Array.prototype.remove = function remove(val, isDelete) {  
            let index = this.indexOf(val)  

            if (index > -1) {  
                let isBack = this.splice(index, 1)  
                return isDelete ? isBack : this  
            }  
            return isDelete ? null : this  
        })  
        App.mpType = 'app'  
        const app = new Vue({  
            // i18n,  
            store,  
            ...App  
        })  

        app.$mount()  

使用

data() {  
        return {  
            list: [  
                '1111',  
                '2222',  
                '3333'  
            ]  
        };  
    },  
methods:{  
delItem(i) {  
    console.log(this.list.remove);  
    this.list.remove(i);  
        }  
}

操作步骤:

main.js

        Vue.config.productionTip = false  
        Array.prototype.remove || (Array.prototype.remove = function remove(val, isDelete) {  
            let index = this.indexOf(val)  

            if (index > -1) {  
                let isBack = this.splice(index, 1)  
                return isDelete ? isBack : this  
            }  
            return isDelete ? null : this  
        })  
        App.mpType = 'app'  
        const app = new Vue({  
            // i18n,  
            store,  
            ...App  
        })  

        app.$mount()  

使用

data() {  
        return {  
            list: [  
                '1111',  
                '2222',  
                '3333'  
            ]  
        };  
    },  
methods:{  
delItem(i) {  
    console.log(this.list.remove);  
    this.list.remove(i);  
        }  
}

预期结果:

能访问到自定义的数组原型上的方法

实际结果:

获取不到自定义的数组原型上的方法

bug描述:

自己在数组原型上添加新的方法,h5和app调试下可以使用,征税运行到APP就找不到原型方法

2022-03-31 11:09 负责人:无 分享
已邀请:
一顾倾人诚

一顾倾人诚

我H5 可以 真机调试就不行了

1***@163.com

1***@163.com -

您解决这个问题了吗

jiangwen1994

jiangwen1994

其他页面通过 this 进行获取不到挂载在原型链上的全局方法,要通过 getApp().xxx 获取挂载在全局的方法

f***@tom.com

f***@tom.com - Decode小白

我也遇到了,请问有解决方案吗

要回复问题请先登录注册