feat(vue-query): 添加 vue-query 示例页面和相关功能

新增 vue-query 示例页面,包含请求演示功能
添加 vue-query 服务层代码和页面跳转逻辑
清理 request.vue 中不再使用的代码注释
This commit is contained in:
feige996
2025-07-16 21:25:38 +08:00
parent 614aadc285
commit feb3d8104b
5 changed files with 84 additions and 12 deletions

View File

@@ -1,8 +1,6 @@
<script lang="ts" setup>
import type { IFooItem } from '@/service/index/foo'
import { getFooAPI } from '@/service/index/foo'
// import { findPetsByStatusQueryOptions } from '@/service/app'
// import { useQuery } from '@tanstack/vue-query'
const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX')
@@ -11,20 +9,11 @@ const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX')
// id: '1234',
// }
const initialData = undefined
// 适合少部分全局性的接口————多个页面都需要的请求接口,额外编写一个 Service 层
const { loading, error, data, run } = useRequest<IFooItem>(() => getFooAPI('菲鸽'), {
immediate: true,
initialData,
})
// 使用 vue-query 的 useQuery 来请求数据,只做参考,是否使用请根据实际情况而定
// const {
// data: data2,
// error: error2,
// isLoading: isLoading2,
// refetch,
// } = useQuery(findPetsByStatusQueryOptions({ params: { status: ['available'] } }))
function reset() {
data.value = initialData
}