Make a npm package by yourself. If you introduce it into the reducer of redux, you will report an error when you package it with webpack.

npm packet address

https://www.npmjs.com/package.

the code is as follows:

module.exports = {
    post: async function(url, headers, postBody) {
        const _self = this;
        var response = [];
        try {
            const response = await fetch(url, {
                method: "POST",
                headers: headers,
                body: postBody,
                mode: "cors",
                credentials: "include"
            })
            return await response.json();

        } catch (e) {
            console.log("Oops, error", e)
        }
    },
    get: async function(url, headers, postBody) {
        const _self = this;
        var response = [];
        try {
            const response = await fetch(url, {
                method: "GET",
                body: postBody,
                headers: headers,
                mode: "cors",
                credentials: "include"
            })
            return await response.json();

        } catch (e) {
            console.log("Oops, error", e)
        }
    }
}
Apr.30,2021
Menu