Javascript实现获取URL地址上携带的参数值。
getQueryString(name) {
const reg = new RegExp('(?<=' + name + '=)[^&]*');
const r = window.location.href.substr(1).match(reg);
if (r != null && r !== undefined) {
return unescape(r[0].match('[^\s]+[^]*')[0]);
}
return null;
}
// 例如地址为
// https://editor.youkuaiyun.com/md?not_checkout=4&spm=10023230.2115.3001.5352&articleId=1333539232326
const not_checkout = getQueryString('not_checkout') // 4
const spm = getQueryString('spm') // 10023230.2115.3001.5352
const articleId = getQueryString('articleId') // 1333539232326