----- 回顾页面跳转方式有哪些:
1.uni.navigateTo 保留当前页面,跳转到应用内的某个页面,使用uni.navigateBack
可以返回到原页面
2.uni.redirectTo 关闭当前页面,跳转到应用内的某个页面
3.uni.reLaunch 关闭所有页面,打开到应用内的某个页面
4.uni.switchTab 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
5. uni.navigateBack关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages()
获取当前的页面栈,决定需要返回几层
----- 跳转带参数:
以uni.navigateTo 为例
1.传递简单数据
//在起始页面跳转到test.vue页面并传递参数
uni.navigateTo({
url: 'test?id=1&name=uniapp'
});
// 在test.vue页面接受参数
export default {
onLoad(option) { //option为object类型,会序列化上个页面传递的参数
console.log(option.id); //打印出上个页面传递的参数。
console.log(option.name); //打印出上个页面传递的参数。
}
}
2.传递复杂数据
let obj = {
test1: 'xxx',
test2: this.xxx,
test3: this.xxx,
test4: this.xxx,
test5: this.xxx
}
uni.navigateTo({
url: `../test/test?info=${encodeURIComponent(JSON.stringify(obj))}`
})
// 在test.vue页面接受参数
export default {
onLoad(option) { //option为object类型,会序列化上个页面传递的参数
console.log('接收到的数据',JSON.parse(decodeURIComponent(option.info)));
}
}