There are two ways for vue routing to set routing parameters :
1. Through query configuration:
-
<router-link :to="{ name:'login',query:{id:1} }">登录</router-link>
-
//通过query配置的路径显示如下:.html#/login?id=1
2. Configure through params :
-
<router-link :to="{ name:'register',params:{'name':'San'} }">注册</router-link>
-
//The path configured by params is displayed as follows: .html#/register/San
The parameters configured by this method need to leave a pit for the parameters when configuring the route, as shown in the following figure:
3. The method of obtaining route parameters:
1.通过query配置的:this.$route.query
2.通过params配置的:this.$route.params
获取加密的路由参数 const params = JSON.parse(this.$Base64.decode(this.$route.query.params.toString()))
// 获取url参数
function getUrlsParams(url) {
console.log(url, 'url')
const temp1 = url.split('?')
const pram = temp1[1]
const keyValue = pram.split('&')
const obj = {}
for (let i = 0; i < keyValue.length; i++) {
const item = keyValue[i].split('=')
const key = item[0]
const value = item[1]
obj[key] = value
}
return obj
}