uniapp页面跳转传递参数过长

6618人阅读 2021/6/14 20:34 总访问:652401 评论:0 收藏:0 手机
分类: uniapp

前言

页面传递参数过长

如果需要传递的参数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;
        }
      }
    });
  },
}


评价
脚踏实地,一步一个脚印
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术