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

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
}
相关推荐
小码哥06813 小时前
【源码集锦】租房小程序技术搭建
小程序·app·租房·租房平台
GMICLOUD13 小时前
Cursor x GMI Cloud 零基础教程:用 Inference Engine 生成你的第一个小程序
人工智能·经验分享·小程序·教程
毕设源码-郭学长14 小时前
【开题答辩全过程】以 火锅点菜小程序为例,包含答辩的问题和答案
小程序
2501_9160088914 小时前
Objective-C 测试(OC 测试)指南 从单元测试到性能调优的多工具协同方法
android·ios·小程序·https·uni-app·iphone·webview
2501_915909061 天前
iOS 上架需要什么东西?一次从准备清单到实操流程的完整技术拆解
android·macos·ios·小程序·uni-app·cocoa·iphone
2501_915921431 天前
抓包技术全面指南:原理、工具与应用场景
android·ios·小程序·https·uni-app·iphone·webview
千寻技术帮1 天前
50043_基于微信小程序的小区物业管理系统
mysql·微信小程序·源码·文档·ppt
hyswl6662 天前
郑州小程序开发公司推荐:详解火焰山科技
科技·小程序
2501_916008892 天前
iOS 性能测试的深度实战方法 构建从底层指标到真实场景回放的多工具测试体系
android·ios·小程序·https·uni-app·iphone·webview
说私域2 天前
基于开源AI智能客服、AI智能名片与S2B2C商城小程序的新社群用户进化策略研究
人工智能·小程序