好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

vue传值的编码和解码方式

vue传值的编码和解码

第一步:传值

编码  encodeURIComponent()

skip(){
? this.$router.push({
? path:'./channelPromotion?channelName='+'我是字?
? 段'+'&&channelUrl='+encodeURIComponent('https://www.baidu.com/#/rejister.........')
? })
}

第二步:取值

解码  decodeURIComponent()

mounted(){
? ? let channelUrl=decodeURIComponent(this.$route.query.channelUrl)
? ? console.log(channelUrl)
}

用vue时前端传值带有特殊符号的,到后台却被转义了

终于解决

废话不多说。之前在写前端时,看了控制台数据传输时正常的10018-001->,但是到了后台直接变成了10018-001-&gt当时抓狂了!!!

最后在伟大的度娘上找到了解决方法!!!!

最后利用java的StringEscapeUtils.unescapeHtml4,成功解决问题!

直接上代码

String s = StringEscapeUtils.unescapeHtml4(bomNo)

接收bomNo进行编译成String的s

这样就行了!!!

引入的包

import org.apache.commons.text.StringEscapeUtils;

maven里pom文件

<dependency>
?? ??? ??? ?<groupId>org.apache.commons</groupId>
?? ??? ??? ?<artifactId>commons-text</artifactId>
?? ??? ??? ?<version>1.1</version>
?? ??? ?</dependency>

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。 

查看更多关于vue传值的编码和解码方式的详细内容...

  阅读:50次