You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
724 B
30 lines
724 B
export const useMyFetch = (request, method="GET" ,opts={}, headers ={}) => {
|
|
const { locale } = useI18n()
|
|
const config = useRuntimeConfig()
|
|
console.log('url',config.public.apiBaseUrl)
|
|
const options = {
|
|
baseURL: config.public.apiBaseUrl,
|
|
method: method,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
// "Authorization": Cookies.get('token'),
|
|
...headers,
|
|
}
|
|
};
|
|
|
|
let data = {
|
|
...opts,
|
|
lang: locale
|
|
}
|
|
|
|
if (method === "GET" || method === "DELETE") {
|
|
options.params = data;
|
|
}
|
|
if (method === "POST" || method === "PUT") {
|
|
options.body = data;
|
|
}
|
|
|
|
return useFetch(request, options)
|
|
}
|
|
|