首页 > 解决方案 > 如何在 vue 路由器中使用冒号 (:)

问题描述

推送后我的网址重新更新我想制作这个网址:

www.abc.com/istanbul-taksim-otelleri?checkin=2019-05-08&checkout=2019-05-16&filters=meal_types:full,half,etc;stars:1,2,4 
const query = {
  checkin: '2019-05-08',
  checkout: '2019-05-16',
  filters:'meal_types:full,half,etc;stars:1,2,4'
}
 this.router.push({query}) 

像这样开始之后

www.abc.com/istanbul-taksim-otelleri?checkin=2019-05-08&checkout=2019-05-16&filters=meal_types%3Afull,half,etc%3Bstars%3A1,2,4

你有什么主意吗 ?怎么解决?

标签: vue.jsvue-router

解决方案


请参阅https://w3schools.com/tags/ref_urlencode.asp -%3A只是一个 URL 编码的冒号。URL 编码字符串是标准做法,并且在大多数情况下需要以生成有效的 URL。

如果您需要对 URL 进行解码,decodeURIComponent()可以使用类似的方法,例如:

const uri = 'www.example.com/:";[]}'

const encodedURI = encodeURIComponent(uri)
console.log(encodedURI)

const decodedURI = decodeURIComponent(encodedURI)
console.log(decodedURI)


推荐阅读