vue中axios的使用詳解
更新時(shí)間:2022年03月17日 16:07:23 作者:小碼哥呀
這篇文章主要為大家詳細(xì)介紹了vue中axios的使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
1、選擇什么網(wǎng)絡(luò)模塊
2、JSONP
3、axios的請(qǐng)求方式
網(wǎng)絡(luò)請(qǐng)求模擬:http://httpbin.org/
4、axios框架的基本使用
1、新建vue項(xiàng)目
vue init webpack learnaxios
2、安裝axios依賴
npm install axiox@0.18.0 --save
3、編寫代碼
import Vue from 'vue' import App from './App' import router from './router' import axios from 'axios' Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, components: { App }, template: '<App/>' }) axios({ url:'http://123.207.32.32:8000/home/multidata' }).then(res=>{ console.log(res); }) axios({ url:'http://123.207.32.32:8000/home/data', // 專門針對(duì)于get請(qǐng)求的參數(shù)拼接 params:{ type: 'pop', page: 3 } }).then(res=>{ console.log(res) })
4、請(qǐng)求結(jié)果
5、axios發(fā)送并發(fā)請(qǐng)求
方式1:
import Vue from 'vue' import App from './App' import router from './router' import axios from 'axios' Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, components: { App }, template: '<App/>' }) // axios發(fā)送并發(fā)請(qǐng)求 axios.all([axios({ url: 'http://123.207.32.32:8000/home/multidata' }),axios({ url:'http://123.207.32.32:8000/home/data', params:{ type:'sell', page:5 } })]).then(response=>{ console.log(response); })
方式2
import Vue from 'vue' import App from './App' import router from './router' import axios from 'axios' Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, components: { App }, template: '<App/>' }) // axios發(fā)送并發(fā)請(qǐng)求 // 方式2 axios.all([axios({ url: 'http://123.207.32.32:8000/home/multidata' }),axios({ url:'http://123.207.32.32:8000/home/data', params:{ type:'sell', page:5 } })]).then(axios.spread((res1,res2)=>{ console.log(res1); console.log(res2); }))
6、axios的配置
6.1、全局配置
6.2、常見(jiàn)的配置選項(xiàng)
總結(jié)
本篇文章就到這里了,希望能夠給你帶來(lái)幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
Vue+Echarts實(shí)現(xiàn)基本K線圖的繪制
這篇文章主要為大家詳細(xì)介紹了如何利用Vue和Echarts實(shí)現(xiàn)基本K線圖的繪制,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-03-03vue中父子組件注意事項(xiàng),傳值及slot應(yīng)用技巧
這篇文章主要介紹了vue中父子組件注意事項(xiàng),傳值及slot應(yīng)用技巧,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-05-05實(shí)現(xiàn)一個(gè) Vue 吸頂錨點(diǎn)組件方法
這篇文章主要介紹了實(shí)現(xiàn)一個(gè) Vue 吸頂錨點(diǎn)組件方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07vue使用Vue.extend方法仿寫個(gè)loading加載中效果實(shí)例
在vue中提供v-loading命令,用于div的loading加載,下面這篇文章主要給大家介紹了關(guān)于vue使用Vue.extend方法仿寫個(gè)loading加載中效果的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06