You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
598 B
29 lines
598 B
import http from 'libs/http'
|
|
import { ref } from 'vue'
|
|
|
|
export default function useApiData(url: string, params?: any, init?: boolean) {
|
|
const data = ref(null)
|
|
const loading = ref(false)
|
|
const error = ref()
|
|
const fetchData = async () => {
|
|
loading.value = true
|
|
error.value = null
|
|
try {
|
|
const response = await http.post(url, params)
|
|
data.value = response.data
|
|
}
|
|
catch (err) {
|
|
error.value = err
|
|
}
|
|
finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
init && fetchData().then(() => {})
|
|
return {
|
|
data,
|
|
loading,
|
|
error,
|
|
fetchData,
|
|
}
|
|
}
|