import { ref } from 'vue' import axios from 'axios' export default function useResource(resource) { console.log('useBlog') axios.defaults.headers.common['app-id'] = '628cbf673800f869ed218152' // for all requests const apiBaseUrl = 'https://628cc5c6a3fd714fd03914c2.mockapi.io/api/' const items = ref([]) const item = ref(null) const fetchAll = async () => { await axios .get(apiBaseUrl + resource) .then((response) => { console.log(response.data) items.value = response.data }) } const fetchOne = async (id) => { console.log('fetchOne', id) await axios .get(`${resource}/${id}`) .then((response) => { item.value = response.data }) } return { items, fetchAll, item, fetchOne } }