userequestdemo 1.0.0
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/dist/userequestdemo.mjs +22 -0
- package/dist/userequestdemo.umd.js +1 -0
- package/package.json +25 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ref as e } from "vue";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
function t(t, n) {
|
|
4
|
+
let { initData: r, onSuccess: i, onError: a } = n, o = e(!1), s = e(null), c = e(r);
|
|
5
|
+
return (async (...e) => {
|
|
6
|
+
o.value = !0, s.value = null;
|
|
7
|
+
try {
|
|
8
|
+
let n = await t(...e);
|
|
9
|
+
c.value = n, i?.(n);
|
|
10
|
+
} catch (e) {
|
|
11
|
+
s.value = e, a?.(e);
|
|
12
|
+
} finally {
|
|
13
|
+
o.value = !1;
|
|
14
|
+
}
|
|
15
|
+
})(), {
|
|
16
|
+
data: c,
|
|
17
|
+
loading: o,
|
|
18
|
+
error: s
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { t as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t(require(`vue`)):typeof define==`function`&&define.amd?define([`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,e.useRequest=t(e.vue))})(this,function(e){function t(t,n){let{initData:r,onSuccess:i,onError:a}=n,o=(0,e.ref)(!1),s=(0,e.ref)(null),c=(0,e.ref)(r);return(async(...e)=>{o.value=!0,s.value=null;try{let n=await t(...e);c.value=n,i?.(n)}catch(e){s.value=e,a?.(e)}finally{o.value=!1}})(),{data:c,loading:o,error:s}}return t});
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "userequestdemo",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A Vue hook for handling HTTP request",
|
|
5
|
+
"main": "dist/userequestdemo.umd.js",
|
|
6
|
+
"module": "dist/userequestdemo.mjs",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"build": "vite build"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"index.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"hook",
|
|
17
|
+
"vue"
|
|
18
|
+
],
|
|
19
|
+
"author": "hapi666",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"vite": "^8.0.1",
|
|
23
|
+
"vue": "^3.5.30"
|
|
24
|
+
}
|
|
25
|
+
}
|