欧美一区2区三区4区公司二百,国产精品婷婷午夜在线观看,自拍偷拍亚洲精品,国产美女诱惑一区二区

axios入門教程

axios入門教程

1、axios是什么

Axios 是一個基于 ?promise的 HTTP 庫,可以用在瀏覽器和 node.js 中。

2、axios如何安裝

(1)使用npm方式進行安裝

npm install axios

(2)使用bower方式進行安裝

bower install axios

(3)使用cdn方式進行安裝

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

3、axios使用案例

(1)get請求方式

將請求參數拼接到url中

const axios = require('axios');
?
axios.get('/user?ID=12345')
? .then(function (response) {
? ? // handle success
? ? console.log(response);
? })
? .catch(function (error) {
? ? // handle error
? ? console.log(error);
? })
? .then(function () {
? ? // always executed
? });
?
?

將請求參數放到params

axios.get('/user', {
? ? params: {
? ? ? ID: 12345
? ? }
? })
? .then(function (response) {
? ? console.log(response);
? })
? .catch(function (error) {
? ? console.log(error);
? })
? .then(function () {
? ? // always executed
? }); ?

?想要使用異步/等待?在外部函數/方法中添加'async關鍵字。?

async function getUser() {
? try {
? ? const response = await axios.get('/user?ID=12345');
? ? console.log(response);
? } catch (error) {
? ? console.error(error);
? }
}

(2)post請求方式

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

?

執行多個并發請求

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) {
? ? //2個post請求現已完成
? }));

4、整合vue-axios

(1)安裝vue-axios

npm install --save axios vue-axios

(2)在main.js中加入

import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
?
Vue.use(VueAxios, axios)

(3)vue-axios使用方法

這里以get請求方式舉例說明,其它請求方式類似。

Vue.axios.get(api).then((response) => {
? console.log(response.data)
})
?
this.axios.get(api).then((response) => {
? console.log(response.data)
})
?
this.$http.get(api).then((response) => {
? console.log(response.data)
})

?

文章鏈接: http://www.qzkangyuan.com/12477.html

文章標題:axios入門教程

文章版權:夢飛科技所發布的內容,部分為原創文章,轉載請注明來源,網絡轉載文章如有侵權請聯系我們!

聲明:本站所有文章,如無特殊說明或標注,均為本站原創發布。任何個人或組織,在未征得本站同意時,禁止復制、盜用、采集、發布本站內容到任何網站、書籍等各類媒體平臺。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。

給TA打賞
共{{data.count}}人
人已打賞
建站教程投稿分享

寶塔的安裝方法

2022-11-10 20:40:04

建站教程投稿分享

錯誤: 找不到或無法加載主類 xxxx

2022-11-17 23:40:30

0 條回復 A文章作者 M管理員
    暫無討論,說說你的看法吧
?
個人中心
購物車
優惠劵
今日簽到
有新私信 私信列表
搜索
主站蜘蛛池模板: 含山县| 延安市| 新民市| 孟连| 宁河县| 砀山县| 邹平县| 秭归县| 吉首市| 汝阳县| 广元市| 大余县| 和平区| 玉林市| 综艺| 奎屯市| 石泉县| 开平市| 大田县| 永仁县| 城市| 含山县| 黄石市| 三台县| 东乡族自治县| 涞水县| 三明市| 新密市| 武夷山市| 福泉市| 绥江县| 石林| 多伦县| 克拉玛依市| 衡东县| 湖口县| 磐石市| 霍城县| 莱芜市| 怀来县| 日土县|