UNPKG

zby-live-sdk

Version:

This is a live SDK for weclassroom.

68 lines (62 loc) 1.54 kB
/* * @Author: songge * @Date: 2020-08-31 16:13:51 * @LastEditTime: 2020-08-31 19:21:52 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \demo9\51-demo\src\_zby_live_sdk\src\network\commonFetch.js */ import axios from 'axios'; import Qs from 'qs'; /** * 真正的请求 * @param url 请求地址 * @param options 请求参数 * @param method 请求方式 */ const get = (params, url, timeout, headers) => { return axios({ method: 'get', url, timeout, params, headers }); }; const post = (data, url, timeout, headers) => { return axios({ method: 'post', url, timeout, data, headers, }); }; const post1 = (data, url, timeout, headers) => { return axios({ method: 'post', url, timeout, data: Qs.stringify(data), headers }); }; function commonFetch(url, options, method = 'GET', timeOut = 60000, headers) { if (method === 'GET') { // 如果是GET请求,拼接url return get(options, url, timeOut, headers).then((res)=>{ return res.data; }); } else if(method === 'POST') { return post(options, url, timeOut, headers).then((res)=>{ return res.data; }); } else if(method === 'FROMDATA') { let headers = { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }; return post1(options, url, timeOut, headers).then((res)=>{ return res.data; }); } } export default commonFetch;