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

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
}
相关推荐
2501_916007473 小时前
iOS性能调试工具终极指南,从系统底层到多端协同的全方位优化实践(2025版)
android·ios·小程序·https·uni-app·iphone·webview
2501_915921433 小时前
iOS崩溃日志深度分析与工具组合实战,从符号化到自动化诊断的完整体系
android·ios·小程序·uni-app·自动化·cocoa·iphone
我很苦涩的10 小时前
使用微信小程序实现多格验证码效果
微信小程序·小程序
阿里花盘10 小时前
花店微信小程序怎么做,创建一个小程序需要多少钱
微信小程序·小程序
2501_9160088911 小时前
没有源码如何加密 IPA 实战流程与多工具组合落地指南
android·ios·小程序·https·uni-app·iphone·webview
LXA080912 小时前
UniApp 小程序中使用地图组件
小程序·uni-app·notepad++
bug总结13 小时前
更新原生小程序封装(新增缓存订阅)完美解决
前端·缓存·小程序
2501_9335090715 小时前
无锡制造企税惠防错指南:知了问账帮守政策红利线
大数据·人工智能·微信小程序
汤姆yu18 小时前
基于微信小程序的智慧社区娱乐服务管理平台
微信小程序·娱乐
2501_9159090619 小时前
Flutter 应用怎么加固,多工具组合的工程化实战(Flutter 加固/Dart 混淆/IPA 成品加固/Ipa Guard + CI)
android·flutter·ios·ci/cd·小程序·uni-app·iphone