解决html路径传参和中文参数乱码问题
众所周知,页面传参在不使用框架的情况下,只能通过url后面的路径传参,并且路径传参不可以传入对象,只能拼接字符串,下面是示例,由于项目是在老项目改动,所以使用到了vue,下面的encodeURI可以对中文字符进行编码,后面的就是要拼接的字符串,做完这些就可以进行跳转了
var searchUrl =encodeURI("individualStandard.html?searchText="+this.selectBox.materialCode
+"&materialName="+this.selectBox.materialName
+"&materialTypeCode="+this.selectBox.materialTypeCode
+"&type="+this.selectBox.type
+"&deptID="+this.selectBox.deptID
+"&unitPrice="+this.selectBox.unitPrice
+"&totalPrice="+this.selectBox.totalPrice
+"&applyNumMax="+this.selectBox.applyNumMax
+"&applyNumPlan="+this.selectBox.applyNumPlan
+"&applyNumRecommend="+this.selectBox.applyNumRecommend
+"&brandOrFirm="+this.selectBox.brandOrFirm
+"&company="+this.selectBox.company
+"&createBy="+this.selectBox.createBy
+"&createOrgId="+this.selectBox.createOrgId
+"&createTime="+this.selectBox.createTime
+"&deptID="+this.selectBox.deptID
+"&enabledState="+this.selectBox.enabledState
+"&historyPrice="+this.selectBox.historyPrice
+"&id="+this.selectBox.id
+"&ip="+this.selectBox.ip
+"&jobID="+this.selectBox.jobID
+"&updateTime="+this.selectBox.updateTime
+"&updateBy="+this.selectBox.updateBy
);
window.location.href = searchUrl
到了新的页面,我是在created里获取参数并且解码的,下方的GetRequest函数最终会生成一个对象,是传参时候的key,value,学会了这俩步,百分百解决页面html跳转传参的问题
created(){
this.gettablelist()
function GetRequest () {
var url = location.search; //获取url中"?"符后的字符串
url=decodeURI(url);
var theRequest = new Object();
if (url.indexOf("?") != -1) {
url = url.split("?")[1];
strs = url.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
}
}
return theRequest;
}
this.creatgetquery=GetRequest()
}