方法1: 父頁面設置鉤子函數(onBackPress):
頁面簡介 | uni-app官網
適用于刷新多處數據
onBackPress(options) {this.refreshData();
},
methods:{refreshData: function() {//加載數據},
},
方法2:?
返回加success回調
uni.navigateBack({delta: 1, //返回層數,2則上上頁success() {uni.$emit('update',{msg:'頁面更新'})},
})
需要刷新的頁面設置:
mounted() {uni.$on('update', function(data) {//觸發更新后})
},
//為了優化代碼,可以加上移除事件,避免重復監聽事件
onUnload() {// 移除監聽事件 uni.$off('update');
},