【发布时间】:2020-08-24 09:46:28
【问题描述】:
我正在从我的 Rails API 后端获取数据,我想要做的是每 15 秒重新加载一次获取请求,所以如果后端发生变化(例如,我在另一条路由中向我的后端发出 post 请求)它重新加载并获取当前数据。
我创建的:
created() {
if (!localStorage.signedIn) {
this.$router.replace("/");
} else {
this.$http.secured
.get("/api/v1/records")
.then(response => {
console.log(response.data);
this.records.splice(0, this.records.length - 1, ...response.data);
})
.catch(error => this.setError(error, "Something went wrong"));
this.$http.secured
.get("/api/v1/templates")
.then(response => {
this.templates = response.data;
})
.catch(error => this.setError(error, "Something went wrong"));
this.$http.secured
.get("/api/v1/data")
.then(response => {
this.datas = response.data;
})
.catch(error => this.setError(error, "Something went wrong"));
}
},
您能帮我实现一个 setInterval 到我的 get 请求吗?
谢谢
【问题讨论】:
标签: javascript api vue.js get reload