- 현우
","language":"javascript"},"rv":2,"parentBlockId":"_root_","sortKey":".o0rr","rt":3},"01kg540zmsr0gcvgqtpwzyshsf":{"id":"01kg540zmsr0gcvgqtpwzyshsf","type":"image","version":3,"value":{"image":{"id":"4dre2n","imageKey":"image/slashpagePost/20260129/235525_BLDRy2deRS3yNrllmh","path":"https://upload.cafenono.com/image/slashpagePost/20260129/235525_BLDRy2deRS3yNrllmh?q=80&s=1280x180&t=outside&f=webp","originalImageSize":{"width":1773,"height":368},"dominantColor":"#25242b","isAnimated":false,"mimeType":"image/png","originalContentLength":35435,"updatedAt":"2026-01-29T14:55:26.000Z","createdAt":"2026-01-29T14:55:25.000Z","domain":{"id":"d3mqew"},"previewHash":"U24_trxvs.t7.Af6RiR%%OfQRiR%-=ogWAWB","page":{"id":"1q3vdn2pxr5x42xy49pr"},"hasTransparentPixels":false,"filename":"image-2026-1-29_18-14-13.png"},"extra":{"isRepresentative":true},"shapeConfigurable":true},"rv":4,"parentBlockId":"_root_","sortKey":".o0u","rt":1},"01kg540zmv1dwdt5w6w35fdd86":{"id":"01kg540zmv1dwdt5w6w35fdd86","type":"text","version":1,"value":{"tokens":[{"text":"데이터를 정상적으로 저장했다면, 데이터 로드는 아래와 같이 컴포저블의 일부 함수를 호출해 바로 불러와줄 수 있다."}]},"rv":3,"parentBlockId":"_root_","sortKey":".o0v","rt":1},"01kg541bgdv9662d2fs2q32n5p":{"id":"01kg541bgdv9662d2fs2q32n5p","type":"code","version":1,"value":{"code":"// Form.vue (로드)\n\n
// useGetAnyInformation.js
const useGetAnyInformation = ({ boardId } ) => {
const get = () => {
const response = api.get(`...?id=${boardId}`);
return response?.data;
}
return useQuery({
queryKey: ['anyInformation', boardId];
queryFn: get
})l
}
// component.vue
<template>
<span> this is information component </span>
<button @click="() => boardId = boardId += 1;">
</template>
<script setup>
import { ref, watch } from 'vue';
const boardId = ref(0);
const { data } = useGetAnyInformation({ boardId: boardId.value });
</script>// useGetAnyInformation.js
const useGetAnyInformation = (getParams) => {
const get = () => {
const { boardId } = getParams();
const response = api.get(`...?id=${boardId}`);
return response?.data;
}
return useQuery({
queryKey: ['anyInformation', boardId];
queryFn: get
})l
}
// component.vue
<template>
<span> this is information component </span>
<button @click="() => boardId = boardId += 1;">
</template>
<script setup>
import { ref, watch } from 'vue';
const boardId = ref(0);
// 매번 함수로 넘겨주면서 리패칭을 하게 되면 boardId를 최신화
const { data, refetch } = useGetAnyInformation(() => { boardId: boardId.value });
// boardId를 감지하기 위해 추가된 부분
watch(boardId, () => {
refetch();
});
</script>// useGetAnyInformation.js
const useGetAnyInformation = (boardIdRef) => {
const get = () => {
const response = api.get(`...?id=${boardIdRef.value}`);
return response?.data;
}
return useQuery({
queryKey: ['anyInformation', boardIdRef];
queryFn: get
})l
}
// component.vue
<template>
<span> this is information component </span>
<button @click="() => boardId = boardId += 1;">
</template>
<script setup>
import { ref, watch } from 'vue';
const boardIdRef = ref(0);
// 매번 함수로 넘겨주면서 리패칭을 하게 되면 boardId를 최신화
const { data, refetch } = useGetAnyInformation(boardIdRef);
</script>...
const queryClient = new QueryClient();
const data = await queryClient,fetchQuery({
queryKey: ['anyInformation', boardId];
queryFn: async () => {
const response = api.get(`...?id=${boardIdRef.value}`);
return response?.data;
}
});
console.log(data) // data.value로 접근을 하는 것이 아니라, 직접 data에 접근하면 된다.// react
const [boardId, setBoardId] = useState('');
useQuery({
queryKey: ['board', boardId], // 일반 문자열로 인식
queryFn: ...
});
// vue
const boardId = ref('');
useQuery({
queryKey: ['board', boardId], // `ref` 반응형 감지
queryFn: ...
});