Compare commits
1 Commits
v1.0.9
...
v1.0.9-rc1
Author | SHA1 | Date | |
---|---|---|---|
eb5b28249f |
@ -1,6 +1,8 @@
|
|||||||
import { useAxios } from '@vueuse/integrations/useAxios'
|
import { useAxios } from '@vueuse/integrations/useAxios'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
|
import { objectToQueryString } from '../utils.js'
|
||||||
|
|
||||||
function getEndpoint() {
|
function getEndpoint() {
|
||||||
const apiMapping = {
|
const apiMapping = {
|
||||||
'': ['http://localhost:28001/', '/api/'],
|
'': ['http://localhost:28001/', '/api/'],
|
||||||
@ -20,7 +22,10 @@ function replaceUrl(url) {
|
|||||||
export function useApiRequest(method, url, data, config = {}) {
|
export function useApiRequest(method, url, data, config = {}) {
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
const baseURL = getEndpoint()
|
const baseURL = getEndpoint()
|
||||||
const fullURL = `${baseURL}${url}`
|
// 若为 GET 请求,将 data 转为查询参数拼接到 URL 上
|
||||||
|
const fullURL = method === 'GET' && data
|
||||||
|
? `${baseURL}${url}?${objectToQueryString(data)}`
|
||||||
|
: `${baseURL}${url}`
|
||||||
const {
|
const {
|
||||||
response,
|
response,
|
||||||
error,
|
error,
|
||||||
|
@ -8,13 +8,13 @@ export const useApiStore = defineStore('api', () => {
|
|||||||
return await execute()
|
return await execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function postData(url, payload) {
|
async function workSimpleSearch(keyword, page = 1) {
|
||||||
const { execute } = useApiRequest('POST', url, payload)
|
const { execute } = useApiRequest('GET', 'search/simple', { keyword, page })
|
||||||
return await execute()
|
return await execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getWork,
|
getWork,
|
||||||
postData,
|
workSimpleSearch
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user