老师,index.html中,应该加下 window.history.replaceState(null, null, `http://${location.host}/game?action=${key}`);,这样实验起来,更加直观点
Object.keys($button).forEach(key => {
$button[key].addEventListener('click', function () {
fetch(`http://${location.host}/game?action=${key}`)
.then((res) => {
window.history.replaceState(null, null, `http://${location.host}/game?action=${key}`);
return res.text()
})
.then((text) => {
$output.innerHTML += text + '<br/>';
})
})
})
展开