ソースを参照

fix: 适配ssg首次加载focus后,js focused.value不同步

Carson 11 ヶ月 前
コミット
e746cfd579
1 ファイル変更4 行追加1 行削除
  1. 4 1
      components/Search/index.vue

+ 4 - 1
components/Search/index.vue

@@ -4,7 +4,7 @@ export default {
 };
 </script>
 <script setup lang="ts">
-import { ref, computed, watch, shallowRef, markRaw, nextTick } from "vue";
+import { ref, computed, watch, shallowRef, markRaw, nextTick, onMounted } from "vue";
 import Mark from 'mark.js/src/vanilla.js'
 import localSearchIndex from '@localSearchIndex'
 import MiniSearch, { type SearchResult } from 'minisearch'
@@ -64,6 +64,9 @@ const searchIndex = computedAsync(async () =>
 const filterText = ref("");
 const input$ = ref();
 const { focused } = useFocus(computed(() => input$.value?.input));
+onMounted(() => {
+  focused.value = true
+})
 const results = shallowRef<(SearchResult & Result)[]>([])
 const loading = ref(false);