1***@qq.com
1***@qq.com
  • 发布:2020-04-24 18:32
  • 更新:2021-08-09 18:21
  • 阅读:1783

【报Bug】往空数组push值报错

分类:HBuilderX

详细问题描述

(DCloud产品不会有明显的bug,所以你遇到的问题大都是在特定环境下才能重现的问题,请仔细描述你的环境和重现方式,否则DCloud很难排查解决你的问题)

[内容]
data() {
return {
hobby:'',
hobbies: [],
bgColor: ['bg-orange', 'bg-olive', 'bg-blue', 'bg-cyan', 'bg-pink', 'bg-red']
};
},
data定义空数组,往数组push报错

重现步骤

{
"message": "this.hobbies.push is not a function",
"stack": "TypeError: this.hobbies.push is not a function\n at VueComponent.confirm (webpack-internal:///./node_modules/babel-loader/lib/index.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/using-components.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-scoped-loader/index.js!F:\线下社交\weiyou-uniapp\pages\tabbar\t5-me\me-hobby-tag\me-hobby-tag.vue?vue&type=script&lang=js&:43:20)\n at click (webpack-internal:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/filter-modules-template.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/page-meta.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-scoped-loader/index.js!F:\线下社交\weiyou-uniapp\pages\tabbar\t5-me\me-hobby-tag\me-hobby-tag.vue?vue&type=template&id=3fd8c203&scoped=true&:89:35)\n at invokeWithErrorHandling (webpack-internal:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.esm.js:1864:26)\n at invoker (webpack-internal:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.esm.js:2189:14)\n at invokeWithErrorHandling (webpack-internal:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.esm.js:1864:26)\n at HTMLElement.invoker (webpack-internal:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.esm.js:2185:9)\n at HTMLElement.original._wrapper (webpack-internal:///./node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.esm.js:7067:25)"
}

[步骤]

[结果]

[期望]

[如果语言难以表述清晰,拍一个视频或截图,有图有真相]

IDE运行环境说明

[HBuilder 或 HBuilderX。如果你用其他工具开发uni-app,也需要在此说明]

[IDE版本号]

[windows版本号]

[mac版本号]

uni-app运行环境说明

[运行端是h5或app或某个小程序?]

[运行端版本号]

[项目是cli创建的还是HBuilderX创建的?如果是cli创建的,请更新到最新版cli再试]

[编译模式说明:自定义组件模式?纯nvue模式?v3模式?]

App运行环境说明

[Android版本号]

[iOS版本号]

[手机型号]

[模拟器型号]

附件

[IDE问题请提供HBuilderX运行日志。菜单帮助-查看运行日志,点右键打开文件所在目录,将log文件压缩成zip包上传]

[App问题请提供可重现问题的代码片段,你补充的细一点,问题就解决的快一点]

[App安装包或H5地址]

[可重现代码片段]

联系方式

[QQ]

2020-04-24 18:32 负责人:无 分享
已邀请:
x***@qq.com

x***@qq.com - 疑问?的小纳?

应该this指向有问题

s***@163.com

s***@163.com

[广告] 18:15:47.709 开源不易,需要鼓励。去给 uni-app 项目 点个 star 吧 [不再提示]
[广告] 18:15:47.710 DCloud 2021新春招聘开启,欢迎前端、Android、C++/QT来投简历! 详情点击
18:15:47.738 项目 '极简登录注册模板' 开始编译...
18:15:50.337 请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。
18:15:50.670 正在编译中...
18:15:52.307 INFO Starting development server...
18:16:08.014 App running at:
18:16:08.015 - Local: http://localhost:8080/
18:16:08.063 - Network: http://192.168.2.103:8080/
18:16:08.063 项目 '极简登录注册模板' 编译成功。前端运行日志,请另行在浏览器的控制台查看。
18:16:08.073 H5版常见问题参考: https://ask.dcloud.net.cn/article/35232
18:16:08.765 App Hide at App.vue:56
18:16:08.920 [HMR] Waiting for update signal from WDS...
18:16:09.120 [system]ReferenceError: Vue is not defined
at Function.success (webpack-internal:///./node_modules/babel-loader/lib/index.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/using-components.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-scoped-loader/index.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/wrap-loader/index.js?!../../../../../xiaochengxu/xcx/syk/App.vue?vue&type=script&lang=js&:8:9)
at http://localhost:88/static/js/chunk-vendors.js:204:85099
at Object.I [as callback] (http://localhost:88/static/js/chunk-vendors.js:204:87946)
at b (http://localhost:88/static/js/chunk-vendors.js:204:88783)
at http://localhost:88/static/js/chunk-vendors.js:204:89683
at O (http://localhost:88/static/js/chunk-vendors.js:204:337146)
at Object.getSystemInfo (http://localhost:88/static/js/chunk-vendors.js:204:518978)
at Vue.onLaunch (webpack-internal:///./node_modules/babel-loader/lib/index.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-uni-app-loader/using-components.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/index.js?!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-scoped-loader/index.js!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/wrap-loader/index.js?!../../../../../xiaochengxu/xcx/syk/App.vue?vue&type=script&lang=js&:5:9)
at invokeWithErrorHandling (http://localhost:88/static/js/chunk-vendors.js:5318:26)
at Vue.push../node_modules/@dcloudio/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.esm.js.Vue.__call_hook (http://localhost:88/static/js/chunk-vendors.js:12060:17)
18:16:09.141 App Launch at App.vue:50
18:16:09.143 App Show at App.vue:53

s***@163.com

s***@163.com

添加了App.vue 的onLaunch 里的 这段代码后报错:
uni.getSystemInfo({
success: function(e) {
// #ifndef MP
Vue.prototype.StatusBar = e.statusBarHeight;
if (e.platform == 'android') {
Vue.prototype.CustomBar = e.statusBarHeight + 50;
} else {
Vue.prototype.CustomBar = e.statusBarHeight + 45;
};
// #endif

                // #ifdef MP-WEIXIN  
                Vue.prototype.StatusBar = e.statusBarHeight;  
                let custom = wx.getMenuButtonBoundingClientRect();  
                Vue.prototype.Custom = custom;  
                Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;  
                // #endif         

                // #ifdef MP-ALIPAY  
                Vue.prototype.StatusBar = e.statusBarHeight;  
                Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;  
                // #endif  
            }  
        })

该问题目前已经被锁定, 无法添加新回复