赞
踩
微信提供了api,开发者可以通过wx.request来获取服务器的数据和传递数据。虽然api提供了很大的方便,但是调用多个接口时,代码重复性太高,我们可以进一步封装。
发起 HTTPS 网络请求
wx.request({ url: 'test.php', // 示例接口 data: { x: '', y: '' }, header: { 'content-type': 'application/json' // 默认值 }, success(res) { console.log(res.data) } })
index.js
const apiHttp = "http://192.168.0.105:7001"; // 需要提前知道后端IP地址
const socketHttp = "wss://*****.com/wss";
function request(url, method, data, header) {
data = data || {
};
header = header || {
};
let token = wx.getStorageSync("token")
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。