uniapp解决首页列表替换数据闪烁问题
解决思路:将列表数据和page缓存,在页面执行onshow时,加载列表,比对缓存的数据和新获取的是否一致,一致的话就不更新。
·
解决思路:将列表数据和page缓存,在页面执行onshow时,加载列表,比对缓存的数据和新获取的是否一致,一致的话就不更新。
需要初始化的参数
page: 1,
limit: 10,
goodList: [],
onShow() {
var that = this;
if(!shop_list){
that.page = 1;
that.goodList = [];
}
that.initData2();
},
initData2() {
console.log('我到底执行了没有');
var that = this;
var url = 'member/shop-goods';
var data = {
page: that.page,
limit: that.limit
}
that.util.asynRequest(url, data, 'post',
function(res) {
console.log(res.data.list);
console.log(res.data.allnum);
that.goodNum = res.data.allnum;
if (res.data.list.length > 0) {
if (that.page == 1) {
uni.setStorageSync('shop_page',that.page)
var shop_list = uni.getStorageSync('shop_list');
console.log('shop_list:',shop_list);
var list = res.data.list;
if(shop_list){
if(shop_list.length == list.length){
var count = 0;
for(var i = 0; i < shop_list.length; i++){
if(shop_list[i].goodsId != list[i].goodsId){
count ++;
}
}
if(count > 0){
that.goodList = list;
uni.setStorageSync('shop_list',list)
}
}else{
uni.setStorageSync('shop_page',1)
that.goodList = res.data.list;
}
}else{
console.log('999999999999');
that.goodList = res.data.list;
uni.setStorageSync('shop_list',res.data.list)
var shop_list = uni.getStorageSync('shop_list');
console.log('shop_list:',shop_list);
}
} else {
var old_page = uni.getStorageSync('shop_page')
if(old_page < that.page){
that.goodList = that.goodList.concat(res.data.list);
uni.setStorageSync('shop_page',that.page)
}
}
} else {
if (that.page > 1) {
that.page--;
uni.setStorageSync('shop_page',that.page)
}else{
that.show_a = true;
that.list = [];
}
if (that.token && that.goodList.length != 0) {
that.util.showToast('暂无更多数据!')
}
}
that.$forceUpdate()
console.log('that.goodList', that.goodList)
},
function(err) {
console.log('==========888=========', err);
if (that.page > 1) {
uni.setStorageSync('shop_page',that.page)
that.page--;
}else{
that.show_a = true;
}
})
},
更多推荐
已为社区贡献8条内容
所有评论(0)