当请求URL时:/ api / v1 / todos
我设置了预加载器。函数todo ()
在todos ()
函数内部被调用。在todo ()
函数内部,请求/ api / v1 / todos / $ {todoId}
也被调用。发生跳跃。预加载器出现,消失。然后出现。如何设置预加载器仅显示在请求/ api / v1 / todos / $ {todoId}
上,而不显示在/ api / v1 / todos /
上。
axios.interceptors.request.use(function(config) {
if (config.url === `/api/v1/todos`) {
document.body.classList.add('preloader');
}
componentDidMOunt() {
this.todos();
}
todos = (idGroupTasks) => {
axios({
url: `/api/v1/todos`,
method: "GET"
})
.then(res => {
this.setState({
todos: res.data
});
this.todo(res.data[0].id)
})
.catch(error => {
console.log(error);
})
}
todo = (idTodo) => {
axios({
url: `/api/v1/todo/{idTodo}`,
method: "GET"
})
.then(res => {
this.setState({
todos: res.data
});
})
.catch(error => {
console.log(error);
})
}