标签:index color str data component decode port tst new
// encodeURI、encodeURIComponent、decodeURI、decodeURIComponent四个用来编码和解码 URI 的函数 // URL截取后面的字符串转换成对象 function GetStr() { var url = location.search; //获取url中"?"符后的字串 var obj = new Object(); if(url.indexOf("?") != -1) {//判断?后面是否有字符 var str = url.substr(1);//从第一个字符开始截取 strs = str.split("&");//以&符号分离 console.log(strs); for(var i = 0; i < strs.length; i++) { //decodeURI:将字符解码 //decodeURIComponent:加密 obj[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]); } } return obj; } console.log(GetStr()); // get请求url拼接参数 export function param(data) { let url = ‘‘ for (let k in data) { let value = data[k] !== undefined ? data[k] : ‘‘ if (k==‘token‘) { url += ‘&‘ + k + ‘=‘ + encodeURIComponent(value) } else { url += ‘&‘ + k + ‘=‘ + value } } return url ? url.substring(1) : ‘‘ }
标签:index color str data component decode port tst new
原文地址:https://www.cnblogs.com/lijh03/p/12575191.html