解决html路径传参和中文参数乱码问题

解决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()
				}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mangoxin1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值