关于javascript:如何为url添加参数要确保旧的参数中不含有新加的参数

44次阅读

共计 290 个字符,预计需要花费 1 分钟才能阅读完成。

export function urlAddParams(params) {
  let str = '';
  let keys = Object.keys(params);
  let len = keys.length - 1;
  keys.forEach((key, index) => {str += key + '=' + params[key] + (index < len ? '&' : '');
  });
  let {origin, pathname, search, hash} = window.location;
  search = search === ''?'?': search +'&';
  return origin + pathname + search + str + hash;
}

正文完
 0