刷新 gin-gonic 中的静态文件

Refresh static files in gin-gonic

我的应用程序使用 Gin Web Framework 执行各种任务,其中之一是提供静态文件 (Vue.js)。 定期调用此 API,然后更新数据库中的数据。 这些数据通过这些静态文件显示。我目前的解决方法是在 Vue.js 部分设置一个定时器功能,每分钟刷新一次页面。

有没有更优雅的方法可以在 API 对数据库进行更改后立即刷新这些静态文件?或者我可能以完全错误的方式接近这个?

这是通过以

的方式制作您的页面来实现的

i) 它可以动态处理数据,add/update 数据如果页面接收到新数据

ii) 在不刷新页面的情况下接收数据的机制这可以通过下面提到的几种方法来完成

  1. I can think of setting up a websocket listening for events on page with updated data like 'EventNewData' with Payload containing data which you can fetch on client and make changes to vue data object

  2. You can skip the page refresh part and make API to fetch data on page, so now instead of page refresh you will be doing a ajax request and can make a smoother user experience. This will use a interval function like you were using without page refresh

  3. You maybe can use HTTP long polling for data updates in which client polls the server requesting new information. The server holds the request open until new data is available. Once available, the server responds and sends the new information.