小程式鴻毛框架(三)資料請求的API封裝

2021-09-26 15:50:41 字數 642 閱讀 8078

這篇單獨講解api的封裝,如果想看資料請求的封裝點資料請求核心封裝,下面請看我的封裝例項

api.js

/*

通過 env 輕鬆切換線上線下介面

*/const local = "";// 本地開發環境

const dev = "";// 線上測試介面

const pro = "";// 正式發布介面

// 0:正式介面 1:測試介面 2:本地介面

const enc = 0;

const host = [pro,dev,local][enc];

let api =

module.exports = api;

例項:pages/index.js

// pages/index.js

const fetcher = require('./server.js');

const api = require('./api.js');

page(,

// 獲取使用者資料

fetchdata();

fetcher.post( api.user_info,param,1 ).then(res=>);

},})

基於小程式的網路請求框架

封裝網路請求類 網路請求類 author zhanghaohao date 2019 6 19 const statuscode success 200 開發者伺服器返回的 http 成功狀態碼 const code success 0 介面請求成功的code const code token ti...

WeChat小程式封裝資料請求

module.exports 生產環境 prod 測試環境 test const require request.js 專案中用到的各種業務介面的封裝 module.exports banner圖介面 getbanner 商品詳情介面 getdetail id true 其他介面.針對wx.requ...

微信小程式 POST請求data資料請求不到

最近開始開發小程式,遇到許多小問題,直奔主題。但是wx.request 並非像jquery中的 ajax 一樣,它還需要開發者在具體情況中做一些調整。在直接傳送post請求時,請求成功,可以觸發success 但是請求到的資料為空。這其中的問題出在https請求的header上。上圖為header未...