File tree Expand file tree Collapse file tree 2 files changed +41
-7
lines changed
Expand file tree Collapse file tree 2 files changed +41
-7
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,37 @@ const { data: blogs } = await useMicroCMSGetList<Blog>({
128128</script>
129129```
130130
131+ #### Use reactive values for query parameters
132+
133+ ``` vue
134+ <template>
135+ <input type="text" v-model="queries.q" />
136+ </template>
137+
138+ <script setup lang="ts">
139+ import type { MicroCMSImage } from 'microcms-js-sdk';
140+
141+ type Blog = {
142+ title: string;
143+ eyecatch: MicroCMSImage;
144+ };
145+
146+ const queries = reactive({
147+ q: '',
148+ fields: ['id', 'title', 'eyecatch'],
149+ });
150+
151+ const { data: blogs, refresh } = await useMicroCMSGetList<Blog>({
152+ endpoint: 'blogs',
153+ queries,
154+ });
155+
156+ watch(queries, () => {
157+ refresh();
158+ });
159+ </script>
160+ ```
161+
131162# LICENSE
132163
133164Apache-2.0
Original file line number Diff line number Diff line change 66} from 'microcms-js-sdk' ;
77import { useFetch , useRuntimeConfig } from 'nuxt/app' ;
88import type { FetchOptions as _FetchOptions } from 'ofetch' ;
9+ import { computed } from 'vue' ;
910
1011import { useMicroCMSUrl } from './useMicroCMSUrl' ;
1112
@@ -41,13 +42,15 @@ const useMicroCMSGet = <T>(
4142 const baseURL = useMicroCMSUrl ( ) ;
4243 const config = useRuntimeConfig ( ) ;
4344
44- const query : MicroCMSQueries | undefined = queries
45- ? {
46- ...queries ,
47- fields : queries . fields ?. toString ( ) ,
48- ids : queries . ids ?. toString ( ) ,
49- }
50- : undefined ;
45+ const query = computed < MicroCMSQueries | undefined > ( ( ) =>
46+ queries
47+ ? {
48+ ...queries ,
49+ fields : queries . fields ?. toString ( ) ,
50+ ids : queries . ids ?. toString ( ) ,
51+ }
52+ : undefined
53+ ) ;
5154
5255 return useFetch < T > ( url , {
5356 ...fetchOptions ,
You can’t perform that action at this time.
0 commit comments