vue中获取url参数
作者:互联网
1、路由获取
this.delivery_asn = this.$route.query.delivery_asn;
2、非路由获取
(1)在js文件中写方法
export function getUrlKey(name,url){
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(url) || [, ""])[1].replace(/\+/g, '%20')) || null
}
(2)在项目文件中引入
import { getUrlKey } from '@/utils';
(3)在项目文件中使用
this.delivery_asn = getUrlKey("delivery_asn ",window.location.href)
如果url中参数base64编码
let path = window.location.href.split("?") //分割url
let href = path[0]+"?"+path[1]
let query = Base64.decode(path[1]) //解码
href = path[0]+"?"+ query //解码后重组
this.delivery_asn = getUrlKey("delivery_asn ",href)
标签:vue,url,getUrlKey,delivery,href,参数,path,asn 来源: https://www.cnblogs.com/required/p/11543652.html