uniapp之页面返回并调用返回页方法

在H5页面我们只需下面这样,但是打包成APP是无效的app需要单独加上一个.$vm

const currentPages = getCurrentPages();
const currentPage = currentPages[currentPages.length - 1];
currentPage[funName] && currentPage[funName]();

最终代码,细心的朋友会发现,下面获取的currentPage,H5和APP是不同的,这是因为app端是先改变路由再跳转页面,而H5端是先跳转页面再改变路由(CurrentPages喻为路由)

/**
 * 返回上一页且调用上一页方法
 * @param {Object} funName 方法名
 */
export function back(funName) {
   
	uni.navigateBack({
   
	  success: () => {
   
	    const currentPages = getCurrentPages();
	    if (currentPages.length >= 2) {
   
		  // #ifdef APP
		  // app 端是先改变路由再跳转页面
	      const currentPage1 = currentPages[currentPages.length - 1];
		  currentPage1.$vm[funName] && currentPage1.$vm[funName]();
		  // #endif
		  // #ifdef H5
		  // H5 端是先跳转页面再改变路由
	      const currentPage2 = currentPages[currentPages.length - 2];
		  currentPage2[funName] && currentPage2[funName]();
		  // #endif
	    }
	  }
	});
}

/**
 * 返回上一页且刷新(上一页有pullDownRefresh方法时)
 */
export function backRefresh() {
   
	back('pullDownRefresh');
}

相关推荐

  1. uniapp页面返回调用返回方法

    2024-01-11 12:28:02       51 阅读
  2. uniapp返回上一刷新数据

    2024-01-11 12:28:02       54 阅读
  3. HTML-VUE页面调用android 客户端网络请求返回数据

    2024-01-11 12:28:02       21 阅读
  4. uniapp先显示提示消息再返回上一

    2024-01-11 12:28:02       36 阅读
  5. 优雅实现uniapp返回上一传参

    2024-01-11 12:28:02       32 阅读
  6. uniapp 返回上一再进入当前mounted不执行

    2024-01-11 12:28:02       46 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-11 12:28:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-11 12:28:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-11 12:28:02       82 阅读
  4. Python语言-面向对象

    2024-01-11 12:28:02       91 阅读

热门阅读

  1. 通过代码代替注解方式注入BEAN

    2024-01-11 12:28:02       57 阅读
  2. 使用云主机时要注意的情况

    2024-01-11 12:28:02       55 阅读
  3. P1643 完美数 题解

    2024-01-11 12:28:02       56 阅读
  4. sqlserver导出数据为excel再导入到另一个数据库

    2024-01-11 12:28:02       68 阅读
  5. 【Machine Learning】Other Stuff

    2024-01-11 12:28:02       44 阅读
  6. 数据结构之红黑树

    2024-01-11 12:28:02       63 阅读