var header = {};
header = buffer.deviceInfo;
header.uin=buffer.userInfo.uin;
求帮助,谢谢
开发工具上一切正常
在以下环境下运行上面三行代码后,打开小程序直接奔溃iphone7plus 微信版本 6.5.3
在以下环境下正常iphone6 微信6.5.18
求帮助,谢谢
var buffer = require("/Buffer.js");
var appInit = function(that){
console.log(“app init ++++++++”);
buffer.shopTypeList = buffer.indexShopTypeList;
buffer.shopTypeListOneMap = buffer.rootShopTypeMap;
buffer.menuRootTypeListMap = buffer.menuRootShopTypeMap;
buffer.indexBannerList = buffer.indexBannerList;
buffer.shopBannerList = buffer.shopBannerList;
buffer.shopCatMapArray = buffer.shopCatMapArray;
console.log(buffer);
that.globalData.buffer = buffer;
}
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
console.log(‘App Launch+++++++++’);
buffer.configUrl = commonConfig.getConfigDomain();
buffer.domain = commonConfig.getHostDomain();
//appInit(this);
//getBaseConfig(this);
//console.log(buffer);
console.log(this);
//var logs = wx.getStorageSync(‘logs’) || []
//logs.unshift(Date.now())
//wx.setStorageSync(‘logs’, logs)
},
function setHeader(buffer)
{
var header = {};
header = buffer.deviceInfo;
header.uin=buffer.userInfo.uin;
/*
header.token = buffer.userInfo.token;
header.lat = buffer.location.lat;
header.lon = buffer.location.lon;
*/
/*
wx.getLocation({
type: ‘gcj02’, //返回可以用于wx.openLocation的经纬度
success: function (res) {
var latitude = res.latitude
var longitude = res.longitude
}
})
*/
return header;
}
其实就是app.js里面的一个变量,
globalData: {
buffer: {},
util: util,
httpPromise: httpPromise,
commonConfig: commonConfig,
}然后注册成globalData里面的buffer属性就是一个全局数据
app.js里面有一个变量 buffer
var buffer = require("/Buffer.js");
onlaunch的时候去服务端拿新的
http.get(buffer.configUrl + “sys/getBaseConfig”)
.then(res => {
//buffer.domain = res.data.domain;
console.log(“get base config +++++++++++”);
console.log(res.data);
console.log(“get base config +++++++++++domain”);
console.log(res.data.domain);
buffer.configUrl = res.data.domain.apiUrl;
buffer.userInfo.cityId = res.data.cityId;
buffer.userInfo.cityName = res.data.cityName;
buffer.userInfo.cityIndex = res.data.cityIndex;
buffer.shopTypeList = res.data.indexShopTypeList;
buffer.shopTypeListOneMap = res.data.rootShopTypeMap;
buffer.menuRootTypeListMap = res.data.menuRootShopTypeMap;
buffer.indexBannerList = res.data.indexBannerList;
buffer.shopBannerList = res.data.shopBannerList;
buffer.shopCatMapArray = res.data.shopCatMapArray;
buffer.flagGetBaseConfig = true;
if (res.data[‘cityList’].length > 0) {
buffer.cityList = res.data[‘cityList’];
}
buffer.indexShopTypeList = res.data.indexShopTypeList;
that.globalData.buffer = buffer;
console.log(“buffer+++++++++++++++”);
console.log(buffer);
util.autoLogin(that, true);
})
.catch(e => {
console.log(e);
buffer.httpRequestTimeOut = true;
that.globalData.buffer = buffer;
});
最后设置成全局变量
that.globalData.buffer = buffer;之所以要在本地保存一份,是因为onlaunch里面去请求服务端是异步的,数据还没返回回来,首页就show了,这个真郁闷,一直不知道如何解决,所以只能在本地存一份
今天测试发现她的手机一打开小程序就奔溃,多奔溃几次微信也奔溃了,郁闷啊,求大神帮忙