Skip to content

Commit 36a7f30

Browse files
authored
Merge pull request #52 from rookie-luochao/base
feat: support generate vue-query hook
2 parents 375ed3b + 0ba62d7 commit 36a7f30

15 files changed

+672
-300
lines changed

openapi-ts-request.config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ export default [
44
{
55
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
66
serversPath: './src/service/app',
7-
requestLibPath: `import { request } from '@/utils/http';\n import { CustomRequestOptions } from '@/interceptors/request';`,
7+
requestLibPath: `import request from '@/utils/request';\n import { CustomRequestOptions } from '@/interceptors/request';`,
88
requestOptionsType: 'CustomRequestOptions',
9+
isGenReactQuery: true,
10+
reactQueryMode: 'vue',
911
isGenJavaScript: false,
1012
},
1113
] as GenerateServiceProps[]

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
"eslint-plugin-vue": "^9.32.0",
149149
"husky": "^8.0.3",
150150
"lint-staged": "^15.2.10",
151-
"openapi-ts-request": "^1.0.1",
151+
"openapi-ts-request": "^1.1.2",
152152
"postcss": "^8.4.49",
153153
"postcss-html": "^1.7.0",
154154
"postcss-scss": "^4.0.9",

pnpm-lock.yaml

+38-105
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/about/components/request.vue

+3-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<!-- http://localhost:9000/#/pages/index/request -->
2626
<wd-button @click="run" class="my-6">发送请求</wd-button>
27-
<view class="h-12">
27+
<view class="h-16">
2828
<view v-if="loading">loading...</view>
2929
<block v-else>
3030
<view class="text-xl">请求数据如下</view>
@@ -37,7 +37,7 @@
3737

3838
<script lang="ts" setup>
3939
import { getFooAPI, postFooAPI, IFooItem } from '@/service/index/foo'
40-
import { findPetsByStatus } from '@/service/app'
40+
import { findPetsByStatusQueryOptions } from '@/service/app'
4141
import { useQuery } from '@tanstack/vue-query'
4242
4343
const recommendUrl = ref('http://laf.run/signup?code=ohaOgIX')
@@ -59,12 +59,7 @@ const {
5959
error: error2,
6060
isLoading: isLoading2,
6161
refetch,
62-
} = useQuery({
63-
queryKey: ['findPetsByStatus'],
64-
queryFn: () => {
65-
return findPetsByStatus({ params: { status: ['available'] } })
66-
},
67-
})
62+
} = useQuery(findPetsByStatusQueryOptions({ params: { status: ['available'] } }))
6863
6964
const reset = () => {
7065
data.value = initialData

0 commit comments

Comments
 (0)