uni-app APP无法获取main.js中自己添加的数组原型上的方法
uni-app APP无法获取main.js中自己添加的数组原型上的方法
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | wini10专业版 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Windows
PC开发环境操作系统版本号:wini10专业版
HBuilderX类型:正式
HBuilderX版本号:3.4.3
手机系统:Android
手机系统版本号:Android 8.0
手机厂商:小米
手机机型:k30pro
页面类型:vue
vue版本:vue2
打包方式:云端
示例代码:
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);
}
}
操作步骤:
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就找不到原型方法
5 回复
我H5 可以 真机调试就不行了
您解决这个问题了吗
其他页面通过 this 进行获取不到挂载在原型链上的全局方法,要通过 getApp().xxx 获取挂载在全局的方法
我也遇到了,请问有解决方案吗