diff --git a/src/components/SearchBar/SearchBar.vue b/src/components/SearchBar/SearchBar.vue index 0048d742..3ef4843a 100644 --- a/src/components/SearchBar/SearchBar.vue +++ b/src/components/SearchBar/SearchBar.vue @@ -2,7 +2,7 @@ import type { HistoryItem, SuggestionItem, SuggestionResponse } from './searchHistoryProvider' import { addSearchHistory, - clearSearchHistory, + clearAllSearchHistory, getSearchHistory, removeSearchHistory, } from './searchHistoryProvider' @@ -21,6 +21,12 @@ const searchHistory = shallowRef([]) const historyItemRef = ref([]) const suggestionItemRef = ref([]) +watch(isFocus, async (focus) => { + // 延后加载搜索历史 + if (focus) + searchHistory.value = getSearchHistory() +}) + function handleInput() { selectedIndex.value = -1 if (keyword.value.length > 0) { @@ -124,15 +130,9 @@ function handleKeyDown() { } function handleClearSearchHistory() { - clearSearchHistory() + clearAllSearchHistory() searchHistory.value = [] } - -watch(isFocus, async (focus) => { - // 延后加载搜索历史 - if (focus) - searchHistory.value = getSearchHistory() -})