标签:一个 ase efault lan 数组 并发 -- pre 选项
1,安装axios=> npm install axios --save
2.在mian.js导入 => import axios from ‘axios‘
3.在mian.js中使用
axios({
// 默认情况下是get请求
url:‘http://123.207.32.32:8000/home/multidata‘,
method:‘get‘
}).then(res => {
console.log(res);
})
axios({
url:"http://123.207.32.32:8000/home/data",
params:{
type:‘pop‘,
page:1
}
}).then(res => {
console.log(res);
})
// Promise.all()
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(results => {
console.log(results);
})
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);
}))
//为减少大量代码的重复可以进行全局配置
axios.defaults.baseURL = ‘http://123.207.32.32:8000‘
axios.defaults.timeout = 5000
axios.all([axios({
url:‘/home/multidata‘
}),axios({
url:‘/home/data‘,
params:{
type:‘sell‘,
page:5
}
})])
标签:一个 ase efault lan 数组 并发 -- pre 选项
原文地址:https://www.cnblogs.com/toprogram/p/12609804.html