美文网首页
移动原生传值给web页url时=转成%3D的解码

移动原生传值给web页url时=转成%3D的解码

作者: 好好学习__天天向上 | 来源:发表于2022-12-22 20:04 被阅读0次

encodeURIComponent和decodeURIComponent(推荐使用)

它用于对URL的组成部分进行个别编码,而不用于对整个URL进行编码。

因此,"; / ? : @ & = + $ , #",这些在encodeURI()中不被编码的符号,在encodeURIComponent()中统统会被编码

示例代码.png
let url = 'aaa?userId=0VqMhXM2fqy10ZchzbKiJw%3D%3D&nickName=张三';
    let arr = url.split('?')[1].split('&');
    for (let i = 0; i < arr.length; i++) {
      let key = arr[i].split('=')[0];
      let value = arr[i].split('=')[1];
      if (key == 'userId') {
        this.userId = decodeURIComponent(value);
      } else if (key == 'nickName') {
        this.nickName = value;
      }
    }
    console.log('this.userId', this.userId);

打印结果


结果.png

相关文章

网友评论

      本文标题:移动原生传值给web页url时=转成%3D的解码

      本文链接:https://www.haomeiwen.com/subject/tstbqdtx.html