30 lines
529 B
JavaScript
30 lines
529 B
JavaScript
|
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
|
||
|
}
|
||
|
}
|