Refactor API requests and update component styles
This commit is contained in:
14
composables/states.ts
Normal file
14
composables/states.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/** 用户信息 **/
|
||||
export const useToken = () =>
|
||||
useState<string>('token', () => {
|
||||
const token = useCookie<string | undefined>('token');
|
||||
return token.value ? 'Bearer ' + token.value : '';
|
||||
});
|
||||
|
||||
/** 热门数据 */
|
||||
export const useHotMeg = () => useState<any>('hotMsg', () => {
|
||||
return {
|
||||
projectType:'',
|
||||
projectTypeTop: ''
|
||||
}
|
||||
});
|
||||
@ -19,13 +19,11 @@ const useServerRequest = async <T>(
|
||||
}
|
||||
},
|
||||
onResponse({ response }) {
|
||||
console.log('response1---', response);
|
||||
if (+response.status === 200 && +response._data.code !== 0) {
|
||||
process.client && ElMessage.error(response._data.msg);
|
||||
}
|
||||
},
|
||||
onResponseError({ response }) {
|
||||
console.log('response2---', response);
|
||||
process.client &&
|
||||
ElMessage.error(
|
||||
isArray(response._data.data.msg)
|
||||
@ -36,7 +34,8 @@ const useServerRequest = async <T>(
|
||||
};
|
||||
// return useFetch<T>(url, { ...defaultOptions, ...opts } as any);
|
||||
// 明确转换返回类型
|
||||
const response = await useFetch<T>(url, { ...defaultOptions, ...opts, key: 'unique-key-' + Date.now(), } as any);
|
||||
const response = await useFetch<T>(url, { ...defaultOptions, ...opts } as any);
|
||||
console.log(url +'-----' + 'response----', response.data.value);
|
||||
return response.data.value as unknown as T;
|
||||
};
|
||||
|
||||
@ -45,9 +44,8 @@ const useServerRequest = async <T>(
|
||||
endpoint: string,
|
||||
config?: Omit<FetchOptions, 'method'>
|
||||
): Promise<T> => {
|
||||
console.log('config----', config);
|
||||
console.log(endpoint + '----' + 'config----', config);
|
||||
|
||||
// @ts-ignore
|
||||
return useServerRequest<T>(endpoint, { ...config, method: 'GET' })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user