【uni-app】携带数据跳转界面


uni-app项目中,页面需要用到上一个页面的数据,这就需要携带数据进行跳转。

创建页面

创建两个页面,profile是前一个页面,queryParticles是下一个页面。
在这里插入图片描述

配置路由跳转

在page.json文件里面配置路由
在这里插入图片描述

{
			"path": "pages/queryParticles/queryParticles",
			"style": {
				"navigationBarTitleText": "课程展示",
				"enablePullDownRefresh": false
			}
		},

跳转页面

写一个click事件,方法是 queryParticles,里面携带“user”的数据

	async queryParticles(user){
			this.localStorage.set("classId",user.classId);
			this.localStorage.set("courseId",user.courseId);
				//判断当前的班课是否可以跳转
				let res = await this.$u.api.getLookBack();
				console.log(res)
				if(res.data.code == "0000"){
					let data={
					'name':user.name,
					'classId':user.classId,
					'courseId':user.courseId
					}
			//这里是携带参数跳转页面的接口
				uni.navigateTo({ 
					url: "/pages/queryParticles/queryParticles?data="+encodeURIComponent(JSON.stringify(data)),
					success: res => {console.log("调用成功")},
					fail: () => {console.log("调用失败")},
					complete: () => {console.log("调用完成")}
				})
				}else{
					// showModal: true, //提示框是否显示
					uni.showToast({
						title: '当前课程不支持回看',
						icon:'none',
						duration: 2000
					});
			}
		},

跳转页面的接口:

	uni.navigateTo({ 
					url: "/pages/queryParticles/queryParticles?data="+encodeURIComponent(JSON.stringify(data)),
					success: res => {console.log("调用成功")},
					fail: () => {console.log("调用失败")},
					complete: () => {console.log("调用完成")}
				})

url:跳转路径,路径后可以带参数。参数与路径之间使用?分隔,参数键与参数值用=相连,不同参数用&分隔;如 ‘path?key=value&key2=value2’,path为下一个页面的路径,下一个页面的onLoad函数可得到传递的参数。

接收数据

//使用onload函数接收参数
  onLoad: function (option) { //option为object类型,会序列化上个页面传递的参数		
		 const Data=JSON.parse(decodeURIComponent(option.data));
		  this.ChapterInfo.class_id=Data.classId;
		  //将classid 和courseID存入缓存中
		  this.localStorage.set("classId", Data.classId);
		  this.ChapterInfo.course_id=Data.courseId;
		  this.localStorage.set("courseId", Data.courseId);
		  this.handleSearch();
      },
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张_Laura

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值