Skip to content

Commit

Permalink
fix: focus after router updated
Browse files Browse the repository at this point in the history
  • Loading branch information
StarHeartHunt committed Nov 1, 2023
1 parent aeb5c6b commit d81f526
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/Table.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { nextTick, ref, watch } from "vue";
import { NInput, NLayout } from "naive-ui";
import { NInput, NLayout, type InputInst } from "naive-ui";
import { storeToRefs } from "pinia";
import { useRouter } from "vue-router";
Expand All @@ -14,9 +14,13 @@ const router = useRouter();
const store = usePageStore();
const { plugins, results } = storeToRefs(store);
const searchKeyword = ref<string>(
props.searchKeyword ? props.searchKeyword : "",
);
if (props.searchKeyword) {
nextTick(() => inputInstRef.value?.focus());
}
const searchKeyword = ref<string>(props.searchKeyword || "");
const inputInstRef = ref<InputInst | null>(null);
const handleSearch = debounce((v: string) => {
router.push({ path: "/search", query: { q: v } });
}, 600);
Expand All @@ -29,6 +33,7 @@ watch(searchKeyword, async (newValue) => {
<template>
<n-layout class="flex justify-end">
<n-input
ref="inputInstRef"
v-model:value="searchKeyword"
class="min-w-1/4"
type="text"
Expand Down

0 comments on commit d81f526

Please sign in to comment.