返回上一頁面並刷新數據
//當前頁面 方法一(不推薦使用) 方法名稱(){ let pages = getCurrentPages(); // 當前頁面 let beforePage = pages[pages.length - 2]; // 上一頁 let options = this.id //傳入的參數 uni.navigateBack({ success: function () { beforePage.resumemy(options); // 執行上一頁的onLoad中 resumemy方法 } }); } //返回的上一頁面中onLoad方法 onLoad(options) { this.resumemy(options.id) } //當前頁面 方法二 (推薦使用) 方法名稱(){ uni.$emit('refreshData','可傳入參數'); uni.navigateBack({ delta: 1 }) } //返回上一頁面中 uniapp在onLoad方法 vue在 mounted 或 created中執行 onLoad(options) { uni.$on('refreshData', ('上頁面傳入的參數') => { this.resumemy(options.id) //返回后調用refreshData 內方法 需要更新的接口數據
})
},
刷新當前頁面
//重新獲取數據 從而刷新當前頁面數據
執行完成后(){
this.獲取數據方法()
}
//強制刷新當前頁面 this.$forceUpdate() //刷新當前頁面 this.$router.go(0)