Просмотр исходного кода

引入防抖机制 (Debounce): 在 inputFn 方法中增加了定时器逻辑

shizhongqi 7 месяцев назад
Родитель
Сommit
e1d7ee6904
1 измененных файлов с 7 добавлено и 3 удалено
  1. 7 3
      ghsApp/src/components/module/app-search.vue

+ 7 - 3
ghsApp/src/components/module/app-search.vue

@@ -83,7 +83,8 @@ export default {
 	},
 	data() {
 		return {
-			search: ""
+			search: "",
+			timer: null
 		};
 	},
 	methods: {
@@ -91,9 +92,12 @@ export default {
 			this.$emit("search", this.search);
 		},
 		inputFn(e) {
-			setTimeout(() => {
+			if (this.timer) {
+				clearTimeout(this.timer);
+			}
+			this.timer = setTimeout(() => {
 				this.$emit("input", this.search);
-			});
+			}, 1150);
 		},
 		inputEmptyFn(e) {
 			this.search = '';