From 5bd046abd8fdab4f6f49564e8ce2f6e4c22d859c Mon Sep 17 00:00:00 2001 From: Yuqi Feng Date: Thu, 25 Aug 2022 14:05:52 +0000 Subject: First release --- plugins/hxfetch.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 plugins/hxfetch.ts (limited to 'plugins/hxfetch.ts') 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, + }, + }; +}); -- cgit v1.2.3