axios學習筆記 2

2021-09-27 07:41:11 字數 1114 閱讀 9526

axios.

create

( 請求頭設定

params:

//請求引數拼接在url上

data:

//請求引數放在請求體上

})

axios***:在請求或響應被處理前攔截

axios.interceptors.request.

use( config=>

,err=>

)實際開發的例子,加上token

let instance = axios.

create()

instance.interceptors.request.

use( config=>

,err=>

)

axios.interceptors.response.

use( res=>

,err=>

)

axios.interceptors.request.

use( config=>

,err=>

) axios.interceptors.response.

use( res=>

,err=>

)無論是請求錯誤,還是響應錯誤,最終都會被catch捕捉到,我們可以進行catch中進行處理

axios.

post

('/post'

,data)

.then

((res)

=>).

catch

(err=>

)

let source = axios.canceltoken.

source()

;axios.

post

('/post',)

.then

((res)

=>).

catch

(err=>

)//取消請求(message 可選)

axios學習筆記

二.axios的post方式請求介面 三.axios的併發 四.axios的自定義例項 五.axios 使用axios前要引入axios檔案 1 axios.get url 獲取資料 then res console.log res 顯示資料 then err promise.reject err ...

axios學習筆記

預設是get請求,params是為get請求傳參時使用 axios then res axios.all axios.all axios axios then result result 為第乙個請求返回的資料和第二個請求返回資料的陣列集合 axios.all axios axios then ax...

axios學習筆記

它是乙個功能強大的網路請求庫 script src script axios.get 位址?key value key2 values then function response function err axios.get 位址?查詢字串 then function response funct...