解决办法
使用encodeURIComponent编码
A页面
//自定义跳转方法
function navigate(category, uuid, index, allInfo) {
wx.navigateTo({
url: `/pages/component/insidePages/${category}/${category}?category=${category}&uuid=${uuid}&index=${index}&allInfo=${allInfo}`,
})
//跳转详情页
_jumpDetails(e) {
console.log(e.currentTarget.dataset);
let type = e.currentTarget.dataset.type
let category = e.currentTarget.dataset.category
let uuid = e.currentTarget.dataset.uuid
let index = e.currentTarget.dataset.index
//allInfo是数组 跳转携带数组需要转换数据格式 JSON.stringify()
let allInfo = encodeURIComponent(JSON.stringify(this.data[`${category}Index`]))
console.log(allInfo);
if (type == 1) {
utils.navigate("anime", uuid, index)
} else {
//跳转 携带四个参数 allInfo是数组
utils.navigate(category, uuid, index, allInfo)
}
B页面
onLoad(options){
//此处接收也需要转换格式
let allInfo = JSON.parse(decodeURIComponent(options.allInfo))
}
总结
1.传参数时先将数组转化为JSON数据格式JSON.stringify(),再编码encodeURIComponent()
2.接收时先编码decodeURIComponent(),再转换格式JSON.parse()