const BASE_URL = 'http://localhost:3000'; const useFetchRequest = (baseUrl) => { baseUrl = baseUrl || BASE_URL; const config = { headers: {} }; const loading = ref(false); const fetchRequest = (url, fetchConfig) => { url = `${BASE_URL}${url}`; fetchConfig = fetchConfig || {}; fetchConfig.method = (fetchConfig.method || 'get').toLocaleUpperCase(); if (!fetchConfig['Content-Type']) { fetchConfig['Content-Type'] = 'application/json'; } fetchConfig = Object.assign(config, fetchConfig); return $fetch(url, fetchConfig).then(async (response) => { console.log(`response:`, response) return response; }).finally(() => { loading.value = false }) } return { loading, fetchRequest } } export default useFetchRequest;