before suspend
This commit is contained in:
29
assets/js/composables/useResource.js
Normal file
29
assets/js/composables/useResource.js
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user