微信小程序页面传参传对象

js 复制代码
// 构建url
const buildUrl = (url, query = {}, isSequence = true) => {
  if (!query) return url;
  const joiner = url.match(/\?/) ? '&' : '?';
  const queryStr = Object.keys(query)
    .map(key => {
      return `${key}=${encodeURIComponent(isSequence?JSON.stringify(query[key]):query[key])}`
    })
    .join('&')
  return url + joiner + queryStr;
}

// 解析query对象
const decodeQuery = (originQuery = {}, isSequence = true) => {
  const result = {};
  if (!originQuery) return {};
  return Object.keys(originQuery).reduce((prev, curr) => {
    result[curr] = decodeURIComponent(originQuery[curr])
    if (isSequence) {
      result[curr] = JSON.parse(result[curr])
    }
    return result;
  }, result)
}

module.exports = {
  buildUrl,
  decodeQuery
}
相关推荐
海石13 小时前
微信小程序开发02:原始人也能看懂的着色器与视频处理
前端·微信小程序·视频编码
li90566328016 小时前
hanzi-writer-miniprogram Path2D问题以及Bug修复
微信小程序·bug
土土哥V_araolin18 小时前
双迪大健康新零售系统开发要点
小程序·个人开发·零售
2501_9159090620 小时前
不用越狱就看不到 iOS App 内部文件?使用 Keymob 查看和导出应用数据目录
android·ios·小程序·https·uni-app·iphone·webview
CHU72903521 小时前
扭蛋机盲盒小程序前端功能设计及核心玩法介绍
前端·小程序
职豚求职小程序1 天前
中华财险笔试测评题库小程序刷题职豚2026新
小程序
阿珊和她的猫1 天前
小程序双线程架构:逻辑层与视图层的协同运作机制
小程序·架构
源码ym7k资源1 天前
在线家政系统(APP+小程序)源码:为您提供专业的本地服务
小程序
2601_952013761 天前
家政服务小程序预约上门服务维修保洁上门服务在线派单技师入驻-ym7K
小程序
2501_915921431 天前
常用iOS性能测试工具大全及使用指南
android·测试工具·ios·小程序·uni-app·cocoa·iphone