问题描述

在uniapp中使用uni.switchTab无法传参

uni.switchTab({
	url:`/pages/report/report?Id=${query}`
})

原因分析

uniapp官方定义uni.switchTab无法传参

参数 类型 必填 说明
url String 需要跳转的 tabBar 页面的路径(需在 pages.json 的 tabBar 字段定义的页面),路径后不能带参数
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

解决方案

使用uni.relaunch可以跳转并携带参数

参数 类型 必填 说明
url String 需要跳转的应用内页面路径 , 路径后可以带参数。参数与路径之间使用?分隔,参数键与参数值用=相连,不同参数用&分隔;如 ‘path?key=value&key2=value2’,如果跳转的页面路径是 tabBar 页面则不能带参数
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)
uni.redirectTo({
	url:`/pages/report/report?Id=${query}`
})

补充:解决uni.switchTab()跳转不刷新

uni.switchTab():不能携带参数,使用uni.switchTab()跳转不会刷新页面

uni.reLaunch:跳转页面会刷新页面

解决办法:

	uni.reLaunch({
			url: '/pages/mine/mine',
			success: function(e) {
				var page = getCurrentPages()[0];
				if (page == undefined || page == null) return;
						page.onLoad(); 
				   }
				})

总结

原文地址:https://blog.csdn.net/qq_58648235/article/details/127141180

相关文章:

  • 2021-12-08
  • 2021-09-22
  • 2022-12-23
  • 2021-10-16
  • 2021-11-17
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-12-30
  • 2021-08-23
  • 2021-09-14
相关资源
相似解决方案