vue2 0 中引入和使用 axios

2021-09-06 20:16:30 字數 950 閱讀 7841

axios 是乙個基於 promise 的 http 庫,可以用在瀏覽器和 node.js 中。

features

從瀏覽器中建立 xmlhttprequests

從 node.js 建立 http 請求

支援 promise api

攔截請求和響應

轉換請求資料和響應資料

取消請求

自動轉換 json 資料

客戶端支援防禦 xsrf 安裝

使用npm安裝

$ npm install axios
example

借用官網的例子

執行 get 請求

// 為給定 id 的 user 建立請求

axios.get('/user?id=12345')

.then(function (response) )

.catch(function (error) );

// 同樣的,上面的請求可以這樣做

axios.get('/user',

}).then(function (response) )

.catch(function (error) );

執行 post 請求
axios.post('/user', )

.then(function (response) )

.catch(function (error) );

執行多個併發請求
function getuseraccount() 

function getuserpermissions()

axios.all([getuseraccount(), getuserpermissions()])

.then(axios.spread(function (acct, perms) ));

vue2 0 按需引入element ui報錯

專案使用vue腳手架自動生成的,vue版本為 2.5.16.專案中需要按需使用element ui,根據element ui的官方文件,一開始在babel.config.js檔案中修改配置 module.exports plugins component 執行專案報錯 error plugins 0...

Vue2 0使用小結

近期第一次使用vue快速開發了一款前端專案,開發效率與便捷性大幅提公升,體驗了一把vue的藝術之道,在此總結下目前所接觸到的vue基礎使用知識,後續會補充遇到的知識點和問題以及解決方案.簡介 vue 是典型mvvm框架,擁有雙向繫結的能力與完整的元件化方案,利用 virtual dom 提供了函式式...

vue2 0建立專案到引入element

一 安裝node環境 提高效率,可以用 的映象 輸入 npm install g cnpm registry 即可安裝npm映象,以後再用到npm的地方直接用cnpm來代替就好了。二 搭建vue專案環境 1 全域性安裝vue cli npm install global vue cli 2 進入你的...