码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【快应用】二级页面如何携带参数返回一级页面?


     【关键词】

    快应用、router、onBackPress

    【问题背景】

    页面栈有A、B两个页面,怎么在B页面中调A页面的方法或传参?场景是:A页面是列表页,B页面是详情页,B页面状态改变后返回A页面状态也要改变。

    【解决方法】

    在onBackPress里重写返回逻辑,通过router.push方式携带参数跳转,A页面在onshow里通过this.param获取(param是push传参的参数名)。

    代码如下:

    A页面:

    1. <style>
    2. .container {
    3. flex-direction: column;
    4. justify-content: center;
    5. align-items: center;
    6. }
    7. .btn {
    8. width: 140px;
    9. height: 60px;
    10. background-color: #00bfff;
    11. border-radius: 28px;
    12. }
    13. .title {
    14. font-size: 50px;
    15. }
    16. style>
    17. <script>
    18. import router from '@system.router'
    19. module.exports = {
    20. data: {
    21. componentData: {},
    22. message: 'Hello World'
    23. },
    24. onInit() {
    25. this.$page.setTitleBar({
    26. text: 'PageA',
    27. textColor: '#ffffff',
    28. backgroundColor: '#007DFF',
    29. backgroundOpacity: 0.5,
    30. menu: true
    31. });
    32. },
    33. onShow(options) {
    34. '// Do something when show.'
    35. console.log(this.messageB + 'this.messageB')
    36. // messageB是B页面携带返回的参数
    37. this.message = this.messageB || this.message
    38. },
    39. onClick() {
    40. router.push({
    41. uri: '/pageB',
    42. params: {message: this.message}
    43. })
    44. }
    45. }
    46. script>

    B页面:

    1. <style>
    2. .container {
    3. flex-direction: column;
    4. justify-content: center;
    5. align-items: center;
    6. }
    7. .btn {
    8. width: 300px;
    9. height: 60px;
    10. margin-bottom: 20px;
    11. background-color: #00bfff;
    12. border-radius: 75px;
    13. }
    14. .title {
    15. font-size: 50px;
    16. }
    17. style>
    18. <script>
    19. import router from '@system.router'
    20. module.exports = {
    21. data: {
    22. componentData: {},
    23. messageB: ''
    24. },
    25. onInit() {
    26. this.$page.setTitleBar({
    27. text: 'PageB',
    28. textColor: '#ffffff',
    29. backgroundColor: '#007DFF',
    30. backgroundOpacity: 0.5,
    31. menu: true
    32. });
    33. },
    34. onShow(options) {
    35. '// Do something when show.'
    36. console.log(this.message + 'this.messageA')
    37. // message 是A页面传过来的值
    38. this.messageB = this.message
    39. },
    40. onClick() {
    41. this.messageB = 'Hello QuickApp'
    42. },
    43. onBackPress() {
    44. console.info(`Triggered:onBackPress`);
    45. router.clear()
    46. router.push({
    47. uri: '/hello',
    48. params: {messageB: this.messageB}
    49. })
    50. }
    51. }
    52. script>

    效果图如下:

    cke_1751.pngcke_2374.pngcke_3071.pngcke_3884.png

  • 相关阅读:
    echars地图---显示到乡镇街道级别
    React---组件进阶
    (六)admin-boot项目之全局处理预防xss攻击
    Hive 表 DML 操作——Hive 表 DML 操作——第1关:将文件中的数据导入(Load)到 Hive 表中
    Github提交和克隆代码步骤记录——图形界面/命令方式
    【音视频】MP4封装格式
    pandas索引操作、赋值操作、排序以及Series排序和DataFrame排序
    如何做好项目管理
    跳跃游戏----题解报告
    学习笔记|矩阵按键控制原理|数值转化为键码|密码锁|STC32G单片机视频开发教程(冲哥)|第十四集:矩阵按键原理及实践
  • 原文地址:https://blog.csdn.net/Mayism123/article/details/132718220
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号