インターネットで多くの方法を検索しましたが、どれもうまくいかなかったので、自分で書いてみました。
// key为url中你想获得的值的key
// 比如url为:http://localhost:8083/#/pages/index/index?ticket=123&debug=1
// 执行 this.getQueryVariable('ticket') 返回 123
Vue.prototype.geKeyValueInUrl = function (key) {
var url = location.href;
console.log('url',url)
var last = '', res = '';
console.log('url.indexOf(key)',url.indexOf(key))
if (url.indexOf(key) > -1) {
last = url.split(key)[1].substr(1)
console.log('last',last)
if(last.indexOf('&') > -1){
res = last.split('&')[0]
}else{
res = last
}
return res;
}else{
return null;
}
};