wx.request
微信小程序原生的网络请求API
1 | wx.request({ |
Promise
使用Promise封装wx.request,在发起一个请求之前使用wx.showToast(),在接口调用结束的complete回调函数中使用wx.hideToast()
1 | const wxRequest = (params = {}, url) => { |
如何使用
编写一个项目的时候,最好把所有的API接口集合一个js文件中
1 | const http = require("../utils/http.js") |
接着,在pages中对应页面的js文件中引入
1 | const api = require('../../api/api.js') |