当前位置: 首页 > news >正文

微信小程序传参过来了,但是数据没有获取到

使用本方法前,已经采用encodeURIComponent把拼接的参数编码之后,拼接在链接上,在接受的页面的onLoad生命周期,接收到参数之后,采用decodeURIComponent进行解码的操作,如果这个也不行,不是说不行,而是第一次跳转没有解析出来数据,也就是页面没有数据。需要第二次跳转才有数据。那么就是在微信小程序中,URL参数传递有以下限制:

  1. 长度限制:URL过长会被截断
  1. 编码问题:特殊字符可能导致解析失败
  1. 生命周期问题:页面加载时序可能影响数据获取

解决方案就是只传递关键的参数。或者跳转过去再做查询功能

传递的参数设置

	clickPatient(item) {if (this.patientInfo) {// 简化方案:只传递最关键的几个参数const params = {patientId: item.patientId || '',brName: item.brName || '',brSfzh: item.brSfzh || '',groupStatus: item.groupStatus || '0',companyCode: item.companyCode || '',rid: item.rid || ''};// 同时使用存储作为备份uni.setStorageSync('current_patient_backup', item);// 构建URL参数const urlParams = Object.keys(params).filter(key => params[key]) // 过滤掉空值.map(key => `${key}=${encodeURIComponent(params[key])}`).join('&');console.log('URL参数字符串:', urlParams);uni.navigateTo({url: `./patientDetail?${urlParams}`,});}},

接受参数设置

onLoad(options) {this.mrPatientInfo = this.$patientInfo.getCurrentPatient()let patientData = null;// 简化方案:直接从URL参数构建数据if (options.patientId) {patientData = {patientId: decodeURIComponent(options.patientId),brName: options.brName ? decodeURIComponent(options.brName) : '',brSfzh: options.brSfzh ? decodeURIComponent(options.brSfzh) : '',groupStatus: options.groupStatus || '0',companyCode: options.companyCode ? decodeURIComponent(options.companyCode) : '',rid: options.rid || ''};}// 备用方案:从存储获取if (!patientData || !patientData.patientId) {try {const backupData = uni.getStorageSync('current_patient_backup');if (backupData && backupData.patientId) {patientData = backupData;// 清理备份数据uni.removeStorageSync('current_patient_backup');}} catch (error) {}}

相关文章:

  • 计算机网络学习笔记:TCP可靠传输实现、超时重传时间选择
  • FPGA基础 -- Verilog 禁止语句
  • 电力物联网,5G/4G通讯终端,电力系统通信
  • openstack的实现原理
  • c++读写锁
  • 基于YOLOv10算法的交通信号灯检测与识别
  • Arduino入门教程:11、直流步进驱动
  • 选择标签词汇功能(单选多选),在文本框展示
  • DeepSeek 助力 Vue3 开发:打造丝滑的日历(Calendar),日历_项目里程碑示例(CalendarView01_22)
  • LeetCode 1358.包含所有三种字符的子字符串数目
  • 暑期前端训练day1
  • 前端适配方案之 flexible.js 到 postcss-px-to-viewport-8-plugin插件演进
  • Windows 10开始菜单优化方案,如何实现Win7风格开始菜单的还原
  • 【设计模式】用观察者模式对比事件订阅(相机举例)
  • 【K8S】详解NodePort 和 ClusterIP
  • 【K8S】详解Labels​​ 和 ​​Annotations
  • Android 应用多语言与系统语言偏好设置指南
  • 容器运行时保护:用Falco构建云原生安全防线
  • 简单理解HTTP/HTTPS协议
  • 基于 Apache POI 实现的 Word 操作工具类
  • 上蔡做网站/嘉兴关键词优化报价
  • 网站的层级/seo模板建站
  • 萧山做网站哪里找/网页是怎么制作的
  • 叫别人做网站安全吗/广州百度推广开户
  • 对我国政府门户网站建设的思考/做博客的seo技巧
  • 政府网站建设考核 邵阳/上海seo推广方法