微信小程序 request请求封装
生活随笔
收集整理的這篇文章主要介紹了
微信小程序 request请求封装
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
request
只用
POST,只封裝了 POST,等有用到 GET再重寫,接口用的 ThinkPHP5.0主要代碼
var apiurl = "xxxxx"; function http_post(controller,data,cb){wx.request({url:apiurl controller,data:data,method:'post',header:{'Content-Type':'application/x-www-form-urlencoded'},success:function(res){return typeof cb == "function" && cb(res.data)},fail:function(res){return typeof cb == "function" && cb(false)}}) } module.exports = {http_post:http_post,//post請求 }前端js使用
var wxq = require('../../utils/wxrequest.js'); var openid = wx.getStorageSync('openid');//獲取緩存里面的openidwxq.http_post('這里是控制器/方法',{'openid':openid},function(res){console.info('回調',res) })原文地址:https://segmentfault.com/a/1190000015996526
更多專業前端知識,請上 【猿2048】www.mk2048.com
總結
以上是生活随笔為你收集整理的微信小程序 request请求封装的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何用纯 CSS 创作一个冒着热气的咖啡
- 下一篇: thinkPHP利用ajax异步上传图片