在H5頁面我們只需下面這樣,但是打包成APP是無效的app需要單獨加上一個.$vm文章來源:http://www.zghlxwxcb.cn/news/detail-781342.html
const currentPages = getCurrentPages();
const currentPage = currentPages[currentPages.length - 1];
currentPage[funName] && currentPage[funName]();
最終代碼,細心的朋友會發(fā)現(xiàn),下面獲取的currentPage,H5和APP是不同的,這是因為app端是先改變路由再跳轉(zhuǎn)頁面,而H5端是先跳轉(zhuǎn)頁面再改變路由(CurrentPages喻為路由)文章來源地址http://www.zghlxwxcb.cn/news/detail-781342.html
/**
* 返回上一頁且調(diào)用上一頁方法
* @param {Object} funName 方法名
*/
export function back(funName) {
uni.navigateBack({
success: () => {
const currentPages = getCurrentPages();
if (currentPages.length >= 2) {
// #ifdef APP
// app 端是先改變路由再跳轉(zhuǎn)頁面
const currentPage1 = currentPages[currentPages.length - 1];
currentPage1.$vm[funName] && currentPage1.$vm[funName]();
// #endif
// #ifdef H5
// H5 端是先跳轉(zhuǎn)頁面再改變路由
const currentPage2 = currentPages[currentPages.length - 2];
currentPage2[funName] && currentPage2[funName]();
// #endif
}
}
});
}
/**
* 返回上一頁且刷新(上一頁有pullDownRefresh方法時)
*/
export function backRefresh() {
back('pullDownRefresh');
}
到了這里,關于uniapp之頁面返回并調(diào)用返回頁方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!