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

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
}
相关推荐
卓怡学长4 小时前
w192基于springboot“考研情报站”微信小程序设计与实现
java·spring boot·spring·微信小程序·intellij-idea
2601_949950635 小时前
练题簿小程序的 4 个功能,把学习资料变成题库
人工智能·小程序·刷题·练习·小程序推荐
Mingprime8 小时前
短时冲刺,孤军奋战,压力山大
小程序
Mingprime9 小时前
孤军奋战那一次
小程序
盟道科技9 小时前
电商小程序购物车系统设计:缓存与数据库双写一致性实战
数据库·缓存·小程序
卓怡学长10 小时前
w193基于springboot“乐通黄骅”电动车智能充电服务小程序
java·spring boot·spring·小程序·intellij-idea
扶风ff19 小时前
新品知识更新太快?用练题簿在线刷题,安排企业培训的小测与复盘
前端·学习·小程序
Ai-_Man1 天前
您您这可以把Microsofat Copilot的多个会话比如说。左侧的多个会话一次性导出吗?不是单条会话里面的多次会对话。AI导出鸭
javascript·人工智能·ai·小程序·电脑·copilot
imperialeast1 天前
创建WAV文件 韩文、德文、俄文等unicode音乐标签
windows·小程序
2601_949950631 天前
错题总是反复错?用练题簿在线刷题,把复习重点找出来
人工智能·小程序·刷题·练习·小程序推荐