日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
axios中如何使用GET與POST

這篇文章主要介紹axios中如何使用GET與POST,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

專業(yè)領(lǐng)域包括網(wǎng)站制作、做網(wǎng)站、商城網(wǎng)站定制開(kāi)發(fā)、微信營(yíng)銷、系統(tǒng)平臺(tái)開(kāi)發(fā), 與其他網(wǎng)站設(shè)計(jì)及系統(tǒng)開(kāi)發(fā)公司不同,創(chuàng)新互聯(lián)建站的整合解決方案結(jié)合了幫做網(wǎng)絡(luò)品牌建設(shè)經(jīng)驗(yàn)和互聯(lián)網(wǎng)整合營(yíng)銷的理念,并將策略和執(zhí)行緊密結(jié)合,為客戶提供全網(wǎng)互聯(lián)網(wǎng)整合方案。

axios

axios 是一個(gè)基于 Promise 的 HTTP 客戶端,專門為瀏覽器和 node.js 服務(wù)

Vue 2.0 官方推薦使用 axios 來(lái)代替原來(lái)的 Vue request,所以這里介紹一下 axios 的功能和基本的使用方法,希望能夠?qū)Ω魑凰袔椭?。^_^

功能

  • 在瀏覽器中發(fā)送 XMLHttpRequests 請(qǐng)求

  • 在 node.js 中發(fā)送 http 請(qǐng)求

  • 支持 Promise API

  • 攔截請(qǐng)求和響應(yīng)

  • 轉(zhuǎn)換請(qǐng)求和響應(yīng)數(shù)據(jù)

  • 取消請(qǐng)求

  • 自動(dòng)轉(zhuǎn)換 JSON 數(shù)據(jù)格式

  • 客戶端支持防范 XSRF 攻擊

瀏覽器支持

axios 能夠支持 IE7 以上的 IE 版本,同時(shí)能夠支持大部分主流的瀏覽器,需要注意的是,你的瀏覽器需要支持 Promise,才能夠使用 axios。所以比較好的做法是先安裝 polyfill,然后再使用 axios。

安裝

Using npm:

$ npm install axios

Using bower:

$ bower install axios

Using cdn:

使用

這里以 Vue 為例:在 NPM 中安裝 axios 之后,需要在 main.js 文件中引用 package

import axios from 'axios'

然后全局綁定

Vue.prototype.$http = axios

然后可以在 .vue 文件中使用 $http 來(lái)代替 axios

GET

// Make a request for a user with a given ID 
axios.get('/user?ID=12345')
 .then(function (response) {
  console.log(response);
 })
 .catch(function (error) {
  console.log(error);
 });

// Optionally the request above could also be done as 
axios.get('/user', {
  params: {
   ID: 12345
  }
 })
 .then(function (response) {
  console.log(response);
 })
 .catch(function (error) {
  console.log(error);
 });

POST

axios.post('/user', {
  firstName: 'Fred',
  lastName: 'Flintstone'
 })
 .then(function (response) {
  console.log(response);
 })
 .catch(function (error) {
  console.log(error);
 });

同時(shí)發(fā)送多個(gè)請(qǐng)求

function getUserAccount() {
 return axios.get('/user/12345');
}

function getUserPermissions() {
 return axios.get('/user/12345/permissions');
}

axios.all([getUserAccount(), getUserPermissions()])
 .then(axios.spread(function (acct, perms) {
  // Both requests are now complete 
 }));

當(dāng)然,axios 的功能還包括 axios API、interceptor 等等,這里想要詳細(xì)了解的可以查看官方文檔:axios,后面陸續(xù)會(huì)介紹下 interceptor 的使用和各類參數(shù)的配置。

以上是“axios中如何使用GET與POST”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!


分享名稱:axios中如何使用GET與POST
轉(zhuǎn)載源于:http://www.dlmjj.cn/article/iichco.html