[{"data":1,"prerenderedAt":63},["ShallowReactive",2],{"content:\u002Fposts\u002F2022\u002Fminiprogram-fetch-data-function":3,"surround:\u002Fposts\u002F2022\u002Fminiprogram-fetch-data-function":52},{"id":4,"title":5,"body":6,"canonical":30,"categories":31,"date":33,"description":30,"draft":34,"extension":35,"image":36,"meta":37,"navigation":38,"path":39,"permalink":30,"readingTime":40,"recommend":30,"references":30,"seo":45,"sitemap":46,"stem":47,"tags":48,"type":30,"updated":33,"__hash__":51},"content\u002Fposts\u002F2022\u002Fminiprogram-fetch-data-function.md","小程序简易请求数据封装",{"type":7,"value":8,"toc":25},"minimark",[9,14],[10,11,13],"h2",{"id":12},"uniapp-请求封装","uniapp 请求封装",[15,16,22],"pre",{"className":17,"code":19,"language":20,"meta":21},[18],"language-js","\u002F\u002F 从配置文件中引入配置好的默认路径\nimport config from \".\u002Fconfig.js\"\n\nclass Request {\n    \u002F**\n     * BASEURL  -> 请求路径（公用）\n     * method -> 请求方式\n     * url -> 请求路径\n     * data -> 请求数据\n     * header -> 请求头\n     * responseType -> 返回数据类型\n     *\u002F\n    request({\n        BASEURL = config.BASEURL,\n        method = \"POST\",\n        url,\n        data,\n        header = { \"Content-Type\": \"application\u002Fjson\" },\n        responseType = \"text\",\n    }) {\n        return new Promise((resolve, reject) => {\n            uni.request({\n                url: `${BASEURL}\u002F${url}`,\n                method,\n                data,\n                header,\n                responseType,\n                success: (res) => {\n                    resolve(res)\n                },\n                fail: (err) => {\n                    reject(err)\n                },\n            })\n        })\n    }\n}\n\nconst http = new Request()\nexport { http }\n","js","",[23,24,19],"code",{"__ignoreMap":21},{"title":21,"searchDepth":26,"depth":26,"links":27},4,[28],{"id":12,"depth":29,"text":13},2,null,[32],"代码","2022-12-04 15:29:02",false,"md","https:\u002F\u002Fbitmc.uno\u002Fpicgo\u002Fminiprogram-fetch-data-function.jpg",{},true,"\u002Fposts\u002F2022\u002Fminiprogram-fetch-data-function",{"text":41,"minutes":42,"time":43,"words":44},"1 min read",0.635,38100,127,{"title":5,"description":30},{"loc":39},"posts\u002F2022\u002Fminiprogram-fetch-data-function",[49,50],"小程序","uniapp","Gm_pWQxEG3e_qH3aq5Jghmju1icY-oTJNDClO_PRiB4",[53,58],{"title":54,"path":55,"stem":56,"date":57,"type":30,"children":-1},"uniapp 接入微信客服","\u002Fposts\u002F2022\u002Fminiprogram-uniapp-servicechat","posts\u002F2022\u002Fminiprogram-uniapp-ServiceChat","2022-12-04 15:28:06",{"title":59,"path":60,"stem":61,"date":62,"type":30,"children":-1},"扫码获取微信抬头","\u002Fposts\u002F2022\u002Fminiprogram-scancode-get-invoice-title","posts\u002F2022\u002Fminiprogram-scancode-get-invoice-title","2022-12-04 15:29:48",1789642597269]