前端 vue中获取地址栏中参数的方法
程序员文章站
2024-02-17 22:33:10
...
getUrl(name,url){
if(!url)
url = location.href;
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var results = regex.exec( url );
return results ==null ? null:results[1]
}
created(){
//name为地址栏中想要的参数名称
this.getUrl('name');
}