document.getElementById('listCategorie').addEventListener('click', (e) => {
axios.get('http://localhost:3001/file/categorieList', {})
.then((response) => {
document.body.innerHTML = '';
document.body.innerHTML = response.data
})
})
我知道如果我使用$(document).on(event,..,..)效果很好,但是不知道为什么。我根本不喜欢使用jquery,只有香草js。我希望将axios响应放入dom中后,所有事件都会继续进行,但它们会消失。
document.body.innerHTML = something || '';
正在替换您的整个身体。因此,请在head标签内添加“ js脚本”
<html>
<head>
<script>...</script> //like this
</head>
<body>...</body>
</html>
或
否则将响应添加到特定元素而不是正文中
document.getElementById('listCategorie').addEventListener('click', (e) => {
axios.get('http://localhost:3001/file/categorieList', {})
.then((response) => {
document.getElementById('app').innerHTML = '';
document.getElementById('app').innerHTML = response.data
})
})