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.
31 lines
723 B
31 lines
723 B
import Cookies from 'js-cookie'
|
|
|
|
export const useRequest = (request, method="GET" ,opts={}, headers ={}) => {
|
|
let locale = Cookies.get('i18n_redirected');
|
|
const config = useRuntimeConfig()
|
|
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 $fetch(request, options)
|
|
}
|
|
|