UNPKG

qw-utils

Version:

qw Utils package

33 lines (32 loc) 707 B
/** * 处理连接 */ class urlUtils { constructor() {} /** * 修改链接的参数值 * @param url 连接 * @param arg 要替换的参数 * @param arg_val 要替换的值 * @returns */ changeURLArg(url, arg, arg_val) { const pattern = arg + '=([^&]*)'; const replaceText = arg + '=' + arg_val; if (url.match(pattern)) { let tmp = '/(' + arg + '=)([^&]*)/gi'; tmp = url.replace(eval(tmp), replaceText); window.history.pushState('', '', tmp); return tmp; } else { if (url.match('[?]')) { return url + '&' + replaceText; } else { return url + '?' + replaceText; } } } } module.exports = { urlUtils };