userequestdemo 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/index.d.ts +3 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
## 使用
|
|
2
|
+
`
|
|
3
|
+
interface Data{
|
|
4
|
+
id:number
|
|
5
|
+
title: string
|
|
6
|
+
content:string
|
|
7
|
+
}
|
|
8
|
+
type Res = {
|
|
9
|
+
code:number,
|
|
10
|
+
messgae:string,
|
|
11
|
+
data:Data[]
|
|
12
|
+
}
|
|
13
|
+
const apiFn = async ():Promise<Res>=>{
|
|
14
|
+
// const apiFn = async function():Promise<Res>{
|
|
15
|
+
const res = await fetch('http://localhost:3000/list/getall',{
|
|
16
|
+
method:"GET",
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
return res.json()
|
|
22
|
+
}
|
|
23
|
+
const handle =()=>{
|
|
24
|
+
const {data,loading,error }=userequestdemo(apiFn,{
|
|
25
|
+
initData:{},
|
|
26
|
+
onSuccess:(data)=>{
|
|
27
|
+
console.log('data1212', data.data.title)
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
`
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
import type { Ref} from 'vue'
|
|
1
3
|
interface Result<T>{
|
|
2
4
|
data: Ref<T>
|
|
3
5
|
loading:Ref<boolean>
|
|
@@ -12,4 +14,4 @@ declare const useRequest:{
|
|
|
12
14
|
(requestFn:(...args:any[])=>Promise<T>, options:Options):Result<T>
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
export default
|
|
17
|
+
export default useRequest
|