반응형
Vuetify : 스로틀/차단 v-autocomplete
원격 데이터와 함께 Vuetify 자동 완성 기능을 사용하고 있는데 API 호출을 제한/해제하고 싶다(500ms 동안 사용자가 자동 완성에서 텍스트를 입력할 때 API를 호출하십시오).내가 어떻게 그럴 수 있을까?
Stack OverFlow라는 게시물이debounce-search
속성, 하지만 내게는 효과가 없었고, 이 속성에 대한 어떤 Vuetify 문서도 보지 못했다.
API 호출을 하는 기능에 디버깅을 추가할 수 있다.신규 통화가 지연되고 보류 중인 모든 통화를 취소하는 등 디베이트가 및 와 함께 이행될 수 있다.
methods: {
fetchEntriesDebounced() {
// cancel pending call
clearTimeout(this._timerId)
// delay new call 500ms
this._timerId = setTimeout(() => {
this.fetch()
}, 500)
}
}
그런 방법은 의 소견으로 감시자에게 속박될 수도 있었다.v-autocomplete
:
<template>
<v-autocomplete :search-input.sync="search" />
</template>
<script>
export default {
data() {
return {
search: null
}
},
watch: {
search (val) {
if (!val) {
return
}
this.fetchEntriesDebounced()
}
},
methods: { /* ... */ }
}
</script>
정말 감사합니다.그건 효과가 있다.여기 내 코드(어드레스 지오코딩)가 있다.
<v-autocomplete
ref="refCombobox"
v-model="adresseSelectionnee"
:items="items"
:loading="isLoading"
:search-input.sync="search"
no-filter
hide-details
hide-selected
item-text="full"
item-value="address"
placeholder="Où ?"
append-icon="search"
return-object
dense
solo
class="caption"
clearable
hide-no-data
></v-autocomplete>
watch: {
search(val) {
if (!val) {
return;
}
this.geocodeGoogle(val);
}
},
methods: {
geocodeGoogle(val) {
// cancel pending call
clearTimeout(this._timerId);
this.isLoading = true;
// delay new call 500ms
this._timerId = setTimeout(() => {
const geocoder = new this.$google.maps.Geocoder();
geocoder.geocode({ address: val, region: "FR" }, (results, status) => {
if (status === "OK") {
this.adressesGoogle = results;
this.isLoading = false;
} else {
this.isLoading = false;
}
});
}, 500);
},
참조URL: https://stackoverflow.com/questions/56821337/vuetify-throttle-debounce-v-autocomplete
반응형
'IT이야기' 카테고리의 다른 글
vue 하위 구성 요소에서 RouteEnter가 작동하지 않음 (0) | 2022.03.24 |
---|---|
Reducx 종속성은 변경되지 않았지만 후속 렌더링 후 useEffect run (0) | 2022.03.24 |
여러 Vuex 경로에서 데이터를 로드하려면 다중 사용 Vue 구성 요소를 어떻게 구성해야 하는가? (0) | 2022.03.24 |
반응형 최초 발사를 탐지하는 방법 (0) | 2022.03.24 |
변수가 python 2 및 3과 호환되는 문자열인지 확인하는 방법 (0) | 2022.03.24 |