Skip to content

Commit

Permalink
当文本框内容变动后超过2秒没有再次变动时触发搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
TCOTC committed Mar 26, 2024
1 parent 650988f commit 74de9b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "siyuan-plugin-hsr-mdzz2048-fork",
"author": "TCOTC",
"url": "https://github.com/TCOTC/siyuan-plugin-hsr-mdzz2048-fork",
"version": "0.0.13",
"version": "0.0.14",
"minAppVersion": "2.9.8",
"backends": ["windows", "linux", "darwin"],
"frontends": ["desktop", "browser-desktop"],
Expand Down
20 changes: 10 additions & 10 deletions src/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
v-model="searchText"
@change="highlightHitResult(searchText)"
@keyup.enter="highlightHitResult(searchText)"
@input="onSearchTextChange"
@input="handleInput"
/>
</div>
{{ resultIndex + "/" + resultCount }}
Expand Down Expand Up @@ -44,15 +44,15 @@ const props = defineProps<{
}>()
// 当文本框内容变动后超过2秒没有再次变动时,会触发 highlightHitResult 函数
let timer: number | null = null;
function onSearchTextChange(value: string) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
highlightHitResult(value);
}, 2000);
// const searchText = ref(''); // v-model 绑定的变量
let typingTimer: number | undefined; // 更新这里,初始化为 undefined
const doneTypingInterval = 2000; // 2秒
function handleInput() {
clearTimeout(typingTimer); // 清除之前的定时器
typingTimer = window.setTimeout(() => { // 使用 window.setTimeout 并更新这里
highlightHitResult(searchText.value); // 使用 .value 访问响应式变量的值
}, doneTypingInterval);
}
Expand Down

0 comments on commit 74de9b6

Please sign in to comment.