import { useFetch, createFetch } from '@vueuse/core';

export function useHttp(url, options = {}, token) {
    const fetch = createFetch(url, {
        baseUrl: '/api/v1',
        options: {
            async beforeFetch({ url, options, cancel }) {
                console.log("asdasd", options)
                options.headers = {
                    ...options.headers,
                    Authorization: `${token}`,
                }
                return {
                    options,
                }
            },
            async afterFetch(ctx) {
                console.log("ctx", ctx)
                // if (ctx.data.code !== 200) {
                //     throw new Error(ctx.data.message || '请求失败');
                // }
                return ctx;
            },
        }
    })
    return fetch(url)
}
