js解决图片缓存刷新

Ft 2021-10-20 AM 32℃ 0条
<body>
  <div id="app">
    <img src="{{url1}}" ></img>
<br>
    <img src="{{url2}}" ></img>
<br>
    <img src="{{url3}}" ></img>
<br>
    <img src="{{url4}}" ></img>
  </div>
</body>
<br>
<center>18:00更新,若异常请稍后刷新(一般不超过20:30).</center>
<script>
  var timestamp = Date.parse(new Date()); 
  var url1 = "x1.png?s="+timestamp;
  var url2 = "x1.png?s="+timestamp;
  var url3 = "x1.png?s="+timestamp;
  var url4 = "x1.png?s="+timestamp;
  let el = document.getElementById('app');
  let template = el.innerHTML;
  let _data = {
    url1: url1,
    url2: url2,
    url3: url3,
    url4: url4
  };

  let data = new Proxy(_data, {
    set(obj, name, value) {
      obj[name] = value;
      render();
    }
  });
  
  render();

  function render() {
    el.innerHTML = template.replace(/\{\{\w+\}\}/g, str => {
      str = str.substring(2, str.length - 2);
      return _data[str];
    });
  }
</script>
您的大名:
万水千山总是情,给个打赏行不行。 打赏
标签: js

非特殊说明,本博所有文章均为博主原创。

评论啦~