uniapp App端切换 Tab 栏列表数据消失问题及解决方案
在H5端的时候,切换tab栏的时候列表数据是存在的,但是在app端的时候切换tab栏列表数据就消失了,可能是因为在app端切换tab栏的时候触发了页面重新渲染,导致列表数据重新初始化为空。解决办法可以尝试以下几种方式:
-
使用vuex进行状态管理:将列表数据保存在vuex中,在切换tab栏时从vuex中获取数据,不受页面重新渲染影响。
-
使用uni-app自带的页面传参功能:在切换tab栏时,将列表数据通过页面传参的方式传递给下一个页面,再返回时再将数据传递回来。
-
使用uni-app自带的页面缓存功能:在切换tab栏时,将当前页面的数据缓存起来,再返回时直接从缓存中获取数据。
-
在app端使用全局变量或者本地存储的方式保存列表数据,在切换tab栏时从全局变量或本地存储中获取数据。
根据具体情况选择合适的方式进行处理,以保证在切换tab栏时列表数据不会消失。
<img :src="technician.photo" mode="heightFix" class="img" />
<view class="right">
<view class="title">{{ technician.userName }}</view>
<view class="category">{{ getType(technician.categoryId) }}</view>
<view class="intro">注册地址: {{ technician.province }}{{ technician.city }}</view>
<view class="" style="text-align: right; padding-top: 5px; padding-right: 10%;">
<button type="primary" size="mini"> 点击查看预约 </button>
</view>
</view>
</view>
if (citys != null) {
requestData.city = citys;
} else {
requestData.city = this.city;
}
requestData.county = this.county;
var locationstr = this.location.split(',');
// 定义两个请求的promise
var promise1 = this.ajax.post(this.jk.mdJsList, requestData);
var promise2 = this.ajax.get(this.jk.mdJsListFen, requestData);
// 使用Promise.all()同时调用两个接口
Promise.all([promise1, promise2])
.then(([result1, result2]) => {
console.log('1111111111111111111111111111')
console.log([result1, result2]);
console.log('222222222222222222222222222');
// 处理第一个接口的结果
this.technicianList = result1.data.records;
// 处理第二个接口的结果
this.storeTypeList = result2.data;
})
},
原文地址: https://www.cveoy.top/t/topic/bjHt 著作权归作者所有。请勿转载和采集!