-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
検索結果画面で2回目以降の検索が反映されるように修正 #195
Conversation
PR Reviewer Guide 🔍
|
PR Code Suggestions ✨Latest suggestions up to 877643f
Previous suggestionsSuggestions up to commit 3e72cd8
|
src/pages/SearchPage.vue
Outdated
@@ -18,7 +16,7 @@ onMounted(() => { | |||
<page-container> | |||
<div :class="$style.container"> | |||
<page-title>検索結果: {{ search }}</page-title> | |||
<user-list :members="users" /> | |||
<user-list :query="search ?? ''" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここで:key="search"
すれば、UserList.vueでwatch
を使わなくてもsearchが変化したときに再取得できるはずです
https://arc.net/l/quote/cnfkhffg
@mehm8128 import { onMounted, watch, ref } from 'vue'
import { User } from '/@/lib/apis'
const search = useQuery('q')
const users = ref<User[]>((await apis.getUsers(undefined, search.value)).data)
watch(search, async () => {
users.value = (await apis.getUsers(undefined, search.value)).data
}) |
普段あんまり使わなくて普通に <suspense :key="search">
<user-list :query="search ?? ''" :users="users" />
<template #fallback>loading...</template>
</suspense>
</div> 僕はVueそんなに詳しいわけではないのでお任せします |
複数のコードを比較してどちらが良いか判断できるほどの知識と技術がないので、どれにするか決めるのはお任せしたいです |
あ〜、Suspenceが効かないのはそうですね… そうなるとめふもさんが提案してくださった実装のほうがよさそうですね 個人的には先に挙げたやり方で行けると思っていたので実装が軽いと想定しちゃってました |
src/pages/SearchPage.vue
Outdated
@@ -18,7 +18,10 @@ onMounted(() => { | |||
<page-container> | |||
<div :class="$style.container"> | |||
<page-title>検索結果: {{ search }}</page-title> | |||
<user-list :members="users" /> | |||
<suspense :key="search"> | |||
<user-list :query="search ?? ''" :members="users" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
すみません僕が前に提示したコードが間違えてて、usersの取得をUserList.vue側で行うようにしてほしいです:pray:(明日ぷぐまくんが教えてくれるっぽいですが、僕のミスなので...)
/improve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
僕もペアプロのときにチェック漏れが発生していてお手数をかけて申し訳ないんですが、この変更をお願いします…!
src/pages/SearchPage.vue
Outdated
<user-list :members="users" /> | ||
<page-title>検索結果: {{ query }}</page-title> | ||
<suspense :key="query"> | ||
<user-list :query="query ?? ''" :search="query ?? ' '" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不必要なqueryを消してほしいということを伝え忘れていたんですが、これもお願いします!
<user-list :query="query ?? ''" :search="query ?? ' '" /> | |
<user-list :query="query ?? ''" /> |
src/components/Search/UserList.vue
Outdated
|
||
interface Props { | ||
members: User[] | ||
search: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あわせてこちらの名称も変更をお願いします
search: string | |
query: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よさそうです、ありがとうございます:kansya_kansya:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修正依頼にも応えてくれてありがとうございます!
お疲れさまでした
User description
close #191
PR Type
Bug fix
Description
src/components/Search/UserList.vue
で、query
プロパティを追加し、APIからユーザーを動的に取得するfetchUsers
関数を実装。src/pages/SearchPage.vue
で、user-list
コンポーネントにquery
プロパティを渡すように変更し、ユーザーの取得ロジックを削除。Changes walkthrough 📝
UserList.vue
ユーザーリストの動的更新を実装
src/components/Search/UserList.vue
ref
とwatch
をインポートquery
プロパティを追加fetchUsers
関数を追加し、APIからユーザーを取得watch
でquery
の変更を監視し、fetchUsers
を呼び出すSearchPage.vue
検索クエリをユーザーリストに渡す処理を修正
src/pages/SearchPage.vue
users
の取得ロジックを削除user-list
コンポーネントにquery
プロパティを渡すように変更