summaryrefslogtreecommitdiff
path: root/plugins/hxfetch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/hxfetch.ts')
-rwxr-xr-xplugins/hxfetch.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/plugins/hxfetch.ts b/plugins/hxfetch.ts
new file mode 100755
index 0000000..c5d85f7
--- /dev/null
+++ b/plugins/hxfetch.ts
@@ -0,0 +1,29 @@
+// Author: Haoxiang Zhao
+
+import { defineNuxtPlugin } from "nuxt/app";
+
+let baseurl: string = "/";
+
+let hxfetch: object = {
+ get: (url: string, payload: object | any) => {
+ let payloadobject = new URLSearchParams(payload);
+ let params: string = payloadobject.toString();
+ return fetch(baseurl.concat(url).concat("?").concat(params), {
+ method: "GET",
+ });
+ },
+ post: (url: string, payload: object) => {
+ return fetch(baseurl.concat(url), {
+ method: "POST",
+ body: JSON.stringify(payload),
+ });
+ },
+};
+
+export default defineNuxtPlugin(() => {
+ return {
+ provide: {
+ hxfetch: hxfetch,
+ },
+ };
+});