vue中axios的使用詳解
更新時間:2022年03月17日 16:07:23 作者:小碼哥呀
這篇文章主要為大家詳細(xì)介紹了vue中axios的使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
1、選擇什么網(wǎng)絡(luò)模塊
2、JSONP
3、axios的請求方式
網(wǎng)絡(luò)請求模擬:http://httpbin.org/
4、axios框架的基本使用
1、新建vue項目
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', // 專門針對于get請求的參數(shù)拼接 params:{ type: 'pop', page: 3 } }).then(res=>{ console.log(res) })
4、請求結(jié)果
5、axios發(fā)送并發(fā)請求
方式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ā)請求 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ā)請求 // 方式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é)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
vue中父子組件注意事項,傳值及slot應(yīng)用技巧
這篇文章主要介紹了vue中父子組件注意事項,傳值及slot應(yīng)用技巧,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-05-05vue使用Vue.extend方法仿寫個loading加載中效果實例
在vue中提供v-loading命令,用于div的loading加載,下面這篇文章主要給大家介紹了關(guān)于vue使用Vue.extend方法仿寫個loading加載中效果的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06