Spookie/assets/js/composables/useResource.js

30 lines
529 B
JavaScript
Raw Normal View History

2022-05-23 16:25:55 +02:00
import { ref } from 'vue'
import axios from 'axios'
export default function useResource(resource) {
console.log('useBlog')
const items = ref([])
const item = ref(null)
const fetchAll = async () => {
await axios
.get(resource)
.then((response) => {
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
}
}