#author("2022-12-25T17:11:14+08:00","default:Admin","Admin") [[uni-app]] #author("2022-12-25T17:13:06+08:00","default:Admin","Admin") &color(red){※前提条件:vue3 的uniapp开发}; #contents 大部分APP的运行错误都是下面的错误开头的 reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack -> * Uncaught TypeError: Cannot read property 'FormData' of undefined [#wde0e682] &color(red){非常重要}; - 因为App的js运行在jscore下而不是浏览器里,没有浏览器专用的js对象,比如document、xmlhttp、cookie、window、location、navigator、localstorage、websql、indexdb、webgl等对象。 - new FormData 也是浏览器定制的对象,只适用于web端,uniapp非H5端不支持 - 【还有】在uni-app中,props是无法访问this的,而在h5中是可以的,所以这个错误会在uni-app的APP端出现,而h5是正常的 - axios 在小程序里用不了 解决方法1: - 使用uniapp 自带的api uni.uploadFile(OBJECT) - 使用flyio https://wendux.github.io/dist/#/doc/flyio/readme #codeprettify{{ XXX }} * Uncaught SyntaxError: Invalid left-hand side in assignment [#pe05cf65] 即左边的参数引用报错。 * 检测到当前使用的ADB不支持反向代理,如果出现连接不上的问题,请更换HBuilder自带的ADB进行真机运行或保持手机和电脑在同一个局域网下 [#de748542] 重新连接一次手机即可 * [Vue warn]: Property or method "toJSON" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties. [#baca428e] 原因不明,解决方法: #codeprettify{{ methods: { toJSON(){ return this; }, }} * navigateTo:fail can not navigateTo a tabbar page [#jabc292d] 原因: navigateTo不能跳转到tarbar的页面 uni.navigateTo 改为 uni.switchTab #codeprettify{{ uni.switchTab({ url: '/pages/index/index', success() { console.log("跳转成功") }, fail(ddd) { console.log("跳转失败"); console.log(ddd); } }) }} * 图标、启动页面设置不起作用 [#c6e76c8a] uniapp的“运行到手机”的话,manifest里面设置的图标等不起作用,只有打包之后才能生效 #hr(); Comment: #comment_kcaptcha