initial
This commit is contained in:
12505
api/Api.ts
Normal file
12505
api/Api.ts
Normal file
File diff suppressed because it is too large
Load Diff
4
api/endpoints/getProductList.ts
Normal file
4
api/endpoints/getProductList.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import api from '~/api/instance'
|
||||
|
||||
export const getProductList = () =>
|
||||
api.wp.v2ProductList()
|
||||
1
api/endpoints/index.ts
Normal file
1
api/endpoints/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './getProductList'
|
||||
14
api/instance.ts
Normal file
14
api/instance.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Api } from '~/api/Api'
|
||||
|
||||
const api = new Api({
|
||||
baseUrl: String('https://wp.koptilnya.xyz/wp-json'),
|
||||
})
|
||||
|
||||
const nativeRequest = api.request
|
||||
|
||||
api.request = async function (...args) {
|
||||
const response = await nativeRequest.call(api, ...args)
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
export default api
|
||||
1
api/queries/index.ts
Normal file
1
api/queries/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './useGetProductList'
|
||||
9
api/queries/useGetProductList.ts
Normal file
9
api/queries/useGetProductList.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { useQuery } from '@tanstack/vue-query'
|
||||
import { getProductList } from '~/api/endpoints'
|
||||
|
||||
export const useGetProductList = () => {
|
||||
return useQuery({
|
||||
queryKey: ['get-product-list'],
|
||||
queryFn: () => getProductList(),
|
||||
})
|
||||
}
|
||||
14
api/useGetProduct.ts
Normal file
14
api/useGetProduct.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { useAsyncData } from '#app'
|
||||
|
||||
export function useGetProducts() {
|
||||
return useAsyncData(
|
||||
'products',
|
||||
async () => {
|
||||
const response = await $fetch('https://wp.koptilnya.xyz/wp-json/wp/v2/product')
|
||||
return response
|
||||
},
|
||||
{
|
||||
server: false,
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user