60秒で自動更新
1 2 3 4 |
<span class="kd">const</span> <span class="nx">timer</span> <span class="o">=</span> <span class="mi">60000</span> <span class="c1">// ミリ秒で間隔の時間を指定</span> <span class="nb">window</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="dl">'</span><span class="s1">load</span><span class="dl">'</span><span class="p">,</span><span class="kd">function</span><span class="p">(){</span> <span class="nx">setInterval</span><span class="p">(</span><span class="dl">'</span><span class="s1">location.reload()</span><span class="dl">'</span><span class="p">,</span><span class="nx">timer</span><span class="p">);</span> <span class="p">});</span> |
イベント実行時に画面も更新
- /stopへリクエストして、5秒後に画面リロード
1 2 3 4 5 6 7 |
<span class="nx">handleClickStop</span><span class="p">()</span> <span class="p">{</span> <span class="kd">const</span> <span class="nx">request</span> <span class="o">=</span> <span class="nx">axios</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span> <span class="na">baseURL</span><span class="p">:</span> <span class="dl">"</span><span class="s2">http://localhost:8080</span><span class="dl">"</span> <span class="p">})</span> <span class="nx">request</span><span class="p">.</span><span class="nx">post</span><span class="p">(</span><span class="dl">"</span><span class="s2">/stop</span><span class="dl">"</span><span class="p">)</span> <span class="nx">setTimeout</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">location</span><span class="p">.</span><span class="nx">reload</span><span class="p">(),</span><span class="mi">5000</span><span class="p">);</span> <span class="p">}</span> |