页面跳转相关
1、页面跳转传参报错
- 问题: 小程序报错 SyntaxError: Unexpected end of JSON inputat JSON.parse ()
- 原因:是由于JSON.parse无法识别某些url中的特殊字符比如&等特殊符号。
- 解决办法:
原来代码:
// 跳转所属专区
clickToTab(item) {
this.$common._jumpToUrl('./modularDetail', 0, { curModular: JSON.stringify(item) })
}
onLoad(data) {
this.curModular = data.curModular ? JSON.parse(data.curModular) : {},
}
现在代码:
// 跳转所属专区
clickToTab(item) {
// #ifndef MP-WEIXIN
this.$common._jumpToUrl('./modularDetail', 0, { curModular: JSON.stringify(item) })
// #endif
// #ifdef MP-WEIXIN
this.$common._jumpToUrl('./modularDetail', 0, { curModular: encodeURIComponent(JSON.stringify(item)) })
// #endif
}
onLoad(data) {
// #ifndef MP-WEIXIN
this.curModular = data.curModular ? JSON.parse(data.curModular) : {}
// #endif
// #ifdef MP-WEIXIN
this.curModular = data.curModular ? JSON.parse(decodeURIComponent(data.curModular)) : {}
// #endif
}