网页无刷新修改参数 静默修改参数

arg参数名 val 修改的参数值

  refreshSilent(arg, val) {
      const url = location.href;
      const pattern = arg + "=([^&]*)";
      const replaceText = arg + "=" + val;
      const replaceUrl = url.match(pattern)
        ? url.replace(eval("/(" + arg + "=)([^&]*)/gi"), replaceText)
        : url.match("[?]")
        ? url + "&" + replaceText
        : url + "?" + replaceText;
      window.history.pushState({}, "", replaceUrl);
    }

使用前

http://192.168.2.97:8080/seniorSearchPage?name=更改请求

调用

refreshSilent("name", "test")

使用后

http://192.168.2.97:8080/seniorSearchPage?name=test

你可能感兴趣的:(网页无刷新修改参数 静默修改参数)