1. After the page jumps back to the previous page, the data is reset and all refreshed.
This is a headache. I did something from page a to page b. When I returned to page a, the previous data was gone. What should I do if the page is reset?
把路由页面跳转时用的
uni.navigateTo({})
改用
uni.navigateBack()
/* 跳转详情页 */
todetail(e) {
var pages = getCurrentPages();// 获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面。
var prevPage = pages[pages.length - 2]; //上一个页面
//prevPage.route获取上一页面的页面路径
//条件编译
console.log(1)
//#ifdef H5
prevPage._data.aa= e.aa//h5中的修改方法
prevPage._data.bb= e.bb//h5中的修改方法
//#endif
// #ifndef H5
prevPage.$vm._data.aa= e.aa//小程序中的修改方法
prevPage.$vm._data.bb= e.bb//小程序中的修改方法
//#endif
uni.navigateBack()//返回上一页面
}
This perfectly solves the problem of automatic page refresh, and is a return method that comes with it;
2. The problem of the page not refreshing.
This is simple. When your data changes, if the page view does not change, you only need to addthis.$forceUpdate()强制刷新页面
//请求接口返回后,强制刷新界面
const result = await this.$request.baseRequest(opts, param);
if (result.status == "000") {
uni.hideLoading()
this.dynamic = this.dynamic.concat(info)
this.$forceUpdate()
} else {
uni.hideLoading()
uni.showModal({
content: result.msg,
showCancel: false
});
}
},