【发布时间】:2020-11-09 13:24:55
【问题描述】:
我在 laravel + VueJS 应用程序中工作。其中有一个搜索功能,用户可以通过它搜索任何文本,然后 API 将根据搜索文本调用以获取数据。所以在 laravel 中调用 API “Fetch API”在 VueJS被使用。所以现在当任何用户按下任何关键字时,每次都会调用该方法以获取结果。因此,由于已经发送了多个请求。我只是喜欢在任何用户键入任何文本时这样做,然后每次之前的请求都必须被取消。我附在下面的代码用于调用API并获取数据。
searchProperties(search) {
if (search != null && search != '') {
this.review = false;
this.clearSes = false;
fetch('/search/' + search)
.then(res => res.json())
.then(res => {
if (res.status === 200) {
this.properties = res.data.properties;
}
});
} else {
this.clearSuggestions();
}
}
提前致谢!
【问题讨论】: