.finally is not a function —— 解決低版本瀏覽器axios不支持finally

歡迎關注前端小謳的github,閱讀更多原創技術文章

框架項目用axios調用接口時,咱們經常使用:前端

接口名().then(result=>{
    do sth...
}).catch(()=>{
    do sth...
}).finally(()=>{
    do sth...
})

卻會遇到這個問題:ios

fName(...).then(...).catch(...).finally is not a function
形成此問題的緣由爲:瀏覽器版本過低

除了升級最新版瀏覽器(火狐甚至升級後還報錯),解決辦法以下:git

安裝 promise.prototype.finally 包
npm i promise.prototype.finally

最後記得在 main.js 裏引入該依賴包:github

require('promise.prototype.finally').shim();
相關文章
相關標籤/搜索