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

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
}
相关推荐
00后程序员张3 分钟前
如何在不同 iOS 设备上测试和上架 uni-app 应用 实战全流程解析
android·ios·小程序·https·uni-app·iphone·webview
微三云-轩38 分钟前
区块链:重构企业数字化的信任核心与创新动力
人工智能·小程序·区块链·生活·我店
阿隆_趣编程3 小时前
为了方便相亲,我用AI写了一款小程序
前端·javascript·微信小程序
2501_9159184121 小时前
iOS 开发全流程实战 基于 uni-app 的 iOS 应用开发、打包、测试与上架流程详解
android·ios·小程序·https·uni-app·iphone·webview
黑马源码库miui5208621 小时前
JAVA同城打车小程序APP打车顺风车滴滴车跑腿源码微信小程序打车源码
java·微信·微信小程序·小程序·uni-app
一口十个小甜虾1 天前
微信小程序体验版,当打开调试模式正常访问,关闭之后无法访问
微信小程序·小程序
悟空码字1 天前
微信开放平台第三方平台,可以管理多个微信小程序
微信·小程序·开放平台
じòぴé南冸じょうげん1 天前
微信小程序如何进行分包处理?
前端·小程序
说私域1 天前
基于开源AI大模型AI智能名片S2B2C商城小程序的参与感构建研究
人工智能·小程序·开源
毕设源码-邱学长2 天前
【开题答辩全过程】以 基于微信小程序的宠物领养系统为例,包含答辩的问题和答案
微信小程序·小程序·宠物