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

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
}
相关推荐
咖啡の猫33 分钟前
微信小程序页面配置
微信小程序·小程序·notepad++
2501_9160088939 分钟前
iOS开发APP上架全流程解析:从开发到App Store的完整指南
android·ios·小程序·https·uni-app·iphone·webview
计算机毕设指导61 小时前
基于微信小程序技术校园拼车系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
计算机毕设指导61 小时前
基于微信小程序求职招聘-兼职管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·求职招聘
咖啡の猫1 小时前
微信小程序全局配置
微信小程序·小程序
喝完这杯奶茶我这离开了1 小时前
微信小程序悬浮毛玻璃导航栏设计详解
微信小程序
biyezuopinvip1 小时前
基于uni-app和Express的问答对战小程序的设计与实现(论文)
小程序·uni-app·毕业设计·论文·express·毕业论文·问答对战小程序的设计与实现
YouEmbedded1 小时前
解码WIFI模块与IoT云平台
stm32·微信小程序·wifi模块(esp8266)·iot云平台接·生态建立
咖啡の猫1 小时前
微信小程序WXML 模板语法
微信小程序·小程序·notepad++
内存不泄露2 小时前
基于协同过滤的旅游景区售票平台及小程序
小程序·旅游