在最近的uniapp社区中发现一个很多人没有解决的一个问题,就是报错:

reportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Uncaught SyntaxError: Unexpected token ‘,’

有时候可以有时候不行,并且报错就是一片空白,其实这个问题很好解决,就是uniapp的this指向问题,废话不多说直接放代码

ces(){// 把this给test变量let test=thisuni.getLocation({type: 'wgs84',success: function (res) {//下面使用test变量就不会报错了test.longitude=res.longitudetest.latitude=res.latitudeconsole.log(test.gg)console.log('当前位置的经度:' + res.longitude);console.log('当前位置的纬度:' + res.latitude);}}); }

由于在uni.getLocation或者别的uniapp提供的api里面无法直接访问this,所以test相当于是一个桥梁