封装一个方法,获取页面url中的参数值?
文章目录
封装一个方法获取页面url参数,可作为框架基础方法使用:
//获取url参数; 正则获取url参数,包含hash[#]和search[?]两种通用
export function getUrlQueryByName(param) {
const reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)');
const r =
window.location.search.substr(1).match(reg) ||
window.location.hash
.substring(window.location.hash.search(/\?/) + 1)
.match(reg);
if (r != null) {
return decodeURIComponent(r[2]);
}
}卡布奇诺今犹在,不见当年倒茶人~😌
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论