updateUrl (key, value) {
let newurl = this.updateQueryStringParameter(key, value)
//向当前url添加参数,没有历史记录
window.history.replaceState({
path: newurl
}, '', newurl);
},
updateQueryStringParameter (key, value) {
let uri = window.location.href
if (!value) {
return uri;
}
let re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
let separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
},
生命周期里 调用 设置参数为 inviteCode
this.updateUrl("inviteCode", 28AT)
![](https://img.haomeiwen.com/i20277786/44890c233b1c632a.png)
ps :
URLSearchParams
https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams
![](https://img.haomeiwen.com/i20277786/bc17d88c812deba8.png)
网友评论