排名
7
文章
192
粉丝
15
评论
16
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

前言
页面传递参数过长
如果需要传递的参数content过长,传递的时候会有问题
所以使用encodeURIComponent来传递
- uni.navigateTo({
- url: `../Fenleicontent/Fenleicontent?content=${encodeURIComponent(JSON.stringify(content))}`
-
- })
接收
如果传递的参数中有%,?,#,&,-,传递时会报错
所以要将危险的值替换掉
- onLoad(option) {
- option.content = this.encodeSearchKey(option.content)
- this.content = JSON.parse(decodeURIComponent(option.content));
- },
- methods: {
- encodeSearchKey(key) {
- const encodeArr = [{
- code: '%',
- encode: '%25'
- }, {
- code: '?',
- encode: '%3F'
- }, {
- code: '#',
- encode: '%23'
- }, {
- code: '&',
- encode: '%26'
- }, {
- code: '=',
- encode: '%3D'
- }];
- return key.replace(/[%?#&=]/g, ($, index, str) => {
- for (const k of encodeArr) {
- if (k.code === $) {
- return k.encode;
- }
- }
- });
- },
- }
评价