第一种方式:hash
http://localhost:8080/#/?user=zhouxiaoye&id=12123213
利用hash去参数
let myUser = ''
let myId = ''
let url = window.location.hash.split('?')[1].split('&')
for (let i = 0; i < url.length; i++) {
let temp = url[i].split('=')
if (temp[0] === 'user') {
myUser = temp[1]
} else if (temp[0] === 'id') {
myId = temp[1]
}
}
console.log('myUser', myUser)
console.log('myId', myId)
第二种方式:href
http://localhost:8080/#/?user=zhouxiaoye&id=12123213
利用hash去参数
let myUser = ''
let myId = ''
let url = window.location.href.split('?')[1].split('&')
for (let i = 0; i < url.length; i++) {
let temp = url[i].split('=')
if (temp[0] === 'user') {
myUser = temp[1]
} else if (temp[0] === 'id') {
myId = temp[1]
}
}
console.log('myUser', myUser)
console.log('myId', myId)
网友评论