当前位置:网站首页>微信小程序返回携带参数或触发事件
微信小程序返回携带参数或触发事件
2022-07-24 05:18:00 【XIE392】
应用场景
点击选择需要跳转到新的页面,在新的页面上选择成功后返回上一个页面,在把选择的结果渲染到上一个页面。
问题描述
微信小程序中返回上一个页面的API是 wx.navigateBack , 这个与 wx.navigateTo有所不同,前者没有 url 提供返回和携带参数,而后者可以在 url 后面携带参数并跳转。那么怎么在返回上一个的页面的同时携带参数回去?
解决方法
例子:A为父页面,B为子页面,B页面需要携带参数返回A页面
A页面
Page({
data: {
name:"张三"
},
test(){
console.log("A页面");
}
})
B页面
let pages = getCurrentPages(); // 获取当前的页面栈
let prevPage = pages[pages.length - 2];
prevPage.setData({
name: "李四" // 需要传递的值
})
prevPage.test(); // 调用 A页面的方法 输出:A页面
wx.navigateBack({
delta:1 //返回上一级页面
})
结果(A页面):
Page({
data: {
name:"张三"
},
test(){
console.log("A页面");
}
onShow(){
console.log("this.data.name"); // 李四
}
})
边栏推荐
- VS 调试
- 整站下载器推荐
- 5.模板缓存,绘制一个正方形只能在三角形内移动
- Mobile software development ISO simple wechat
- Redis的使用
- canvas - 填充
- Draw a circle and a square on the screen. The square is in front and the circle is behind. You can move the square through the keyboard. In the following cases, the square can only move within the cir
- pycharm 配置局域网访问,局域网无法访问解决办法
- 项目免费部署到公网(内网穿透)
- 新语法01_Es6新语法
猜你喜欢
随机推荐
MQTT学习
设计一个函数print打印字符串,如果只传string型参数s,则字符串长度跟10比较,大于10,打印前10个字符,小于10,全部输出s;如果传string型参数s和int型n,则字符串长度跟n比
构造函数_Date构造函数
牛客网刷题
JS - 计算直角三角形的边长及角度
16进制转rgb
libc.so.6/glibc交叉编译
作用域与作用域链
Promise
Scikit learn notes
赶紧进来!!带你了解什么是多文件,并轻松掌握 extern和static c语言关键字的用法!!!
7. 在屏幕上绘制一条贝塞尔曲线,并用反走样技术对曲线进行平滑处理。
还原ui设计稿
Find the flops of the network
special effects - 鼠标点击,出现随机颜色的爱心
ros启动非本机节点
select_ Render small phenomena
MySQL的使用
Mobile software development ISO simple wechat
Ain 0722 sign in









