[英]Reloading Hulu with Chrome Devtools open causes strange behavior
[英]Inconsistent behavior with setTimeout when Chrome DevTools is not open
我的目的是創建一個基本的去抖動 function 來搜索員工。 我發現當 Chrome DevTools 打開時,我可以始終從服務器獲取搜索結果,但是當 Chrome DevTools 未打開時,很多時候服務器上搜索方法中設置的斷點永遠不會被命中。 似乎無論出於何種原因都沒有進行 AJAX 調用。
在codepen下面,不幸的是我沒有可以返回搜索結果的部分。
https://codepen.io/jgunawan-dc/pen/vYLZbEY
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: {
searchInput: null,
selectedEmployees: null,
isSearchingEmployee: false,
items: [],
},
methods: {
searchEmployees: function (searchInput) {
// cancel pending call
clearTimeout(this._timerId);
this.isSearchingEmployee = true;
// delay new call 1 second
this._timerId = setTimeout(() => {
let _this = this,
url = 'some_url' + '?phrase=' + searchInput;
url = encodeURI(url);
$.ajax({
type: 'GET',
url: url,
success: function (result) {
_this.items.splice(0);
_this.items.push(...result);
},
complete: function (xhr) {
_this.isSearchingEmployee = false;
}
});
}, 1000);
}
},
watch: {
'searchInput': function (newVal) {
this.searchEmployees(newVal);
}
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.