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

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
}
相关推荐
胡西风_foxww4 小时前
微信小程序转Vue2组件智能提示词
微信小程序·小程序·提示词·智能体·vue2组件
七七软件开发5 小时前
一对一交友小程序 / APP 系统架构分析
java·python·小程序·系统架构·php
2501_916007477 小时前
iPhone查看App日志和系统崩溃日志的完整实用指南
android·ios·小程序·https·uni-app·iphone·webview
说私域9 小时前
基于开源链动2+1模式AI智能名片S2B2C商城小程序的私域流量拉新策略研究
人工智能·小程序·开源
2501_9159184110 小时前
iOS 抓不到包怎么办?全流程排查思路与替代引导
android·ios·小程序·https·uni-app·iphone·webview
七七软件开发11 小时前
团购商城 app 系统架构分析
java·python·小程序·eclipse·系统架构·php
七七软件开发11 小时前
打车小程序 app 系统架构分析
java·python·小程序·系统架构·交友
换日线°21 小时前
css 不错的按钮动画
前端·css·微信小程序
说私域21 小时前
从渠道渗透到圈层渗透:开源链动2+1模式、AI智能名片与S2B2C商城小程序的协同创新路径研究
人工智能·小程序·开源
qq_427506081 天前
JavaScript和小程序写水印的方法示例
前端·算法·微信小程序