简单的二次封装axios中的get,post方法
生活随笔
收集整理的這篇文章主要介紹了
简单的二次封装axios中的get,post方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
function Axios(type, url, data, header) {/*** 參數:* 1、type:調用axios的方法(get,post……)* 2、url:請求地址* 3、data:傳的參數* 4、header請求頭*/// 這里處理type大小寫type = type.toLocaleLowerCase()switch (type) {case ('get'):return axios({method: type,url,params: data,})case ('post')://地址中有“?”替換為“”url = url.replace('?', '')// new一個表單對象let dated = new FormData();// 拿到所有參數的key值const arr = Object.keys(data)// 將參數的key,value添加至表單對象arr.map(v => {dated.append(v, data[v]);})return axios({method: type,url,data: dated})}
}
總結
以上是生活随笔為你收集整理的简单的二次封装axios中的get,post方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言 单链表查找出倒数第,查找单链表倒
- 下一篇: 湖北首富雷军排不上吗 严格来说雷军就是湖