关于通过前端链接传参时,参数中有 (@、空格、中文字符、:、#、&、=、?等)特殊字符时参数会传过去后会变的坑!
一、先通过发生的JavaScript 中的 encodeURIComponent函数编码
var paramValue = 'abc@123'; //参数
var encodedValue = encodeURIComponent(paramValue); //对参数进行编码
var url = 'http://localhost:8080/?param=' + encodedValue; //跳转的链接和参数
window.open(url,"_blank") //发起带参数的跳转链接
二、再通过接收端使用decodeURIComponent 函数对参数值进行解码
var url = window.location.href; //获取地址栏的url地址信息
var encodedValue = =url.split('=')[1] //截取获取,编码后的参数
var paramValue = decodeURIComponent(encodedValue); //解码
console.log(paramValue); // 输出 abc@123