赞
踩
import { requests } from './config' const BaseUrl = requests.prodUrl+ 'wxapi/' //接口地址 export const Fetch = ({ url = '', data = {}, header = { 'content-type': 'application/json' }, method = 'POST' }) => { return new Promise((resolve, reject) => { wx.getNetworkType({ // 获取当前网络 success: function (reg) { if (reg.networkType != 'none') {//有网的情况下 wx.request({ url: BaseUrl + url, header: Object.assign(header, { sessionId: sessionId }), method: method, data: data, success: res => { // 成功时的处理 if (res.statusCode == 200) { let rcode = res.data.code if (rcode == '0000') { resolve(res.data) } } else { reject(res.data) } }, fail: err => { console.log(err) reject(err) } }) } else { wx.showToast({ title: '请检查当前网络', icon: 'none' }) } } }) }) }
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。