userequestdemo 1.0.2 → 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.
Files changed (3) hide show
  1. package/README.md +31 -0
  2. package/index.d.ts +17 -0
  3. package/package.json +1 -2
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 ADDED
@@ -0,0 +1,17 @@
1
+
2
+ import type { Ref} from 'vue'
3
+ interface Result<T>{
4
+ data: Ref<T>
5
+ loading:Ref<boolean>
6
+ error: Ref<Error| null>
7
+ }
8
+ interface Options{
9
+ initData?:any,
10
+ onSuccess?:(data:any)=>void,
11
+ onError?:(error:Error)=>void
12
+ }
13
+ declare const useRequest:{
14
+ (requestFn:(...args:any[])=>Promise<T>, options:Options):Result<T>
15
+ }
16
+
17
+ export default useRequest
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "userequestdemo",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A Vue hook for handling HTTP request",
5
5
  "main": "dist/userequestdemo.umd.js",
6
6
  "module": "dist/userequestdemo.mjs",
7
- "types": "dist/index.d.ts",
8
7
  "scripts": {
9
8
  "test": "echo \"Error: no test specified\" && exit 1",
10
9
  "build": "vite build"