Vue-axios的基本使用 一
axios请求方式
支持多种请求方式:
- axios(config)
- axios.request(config)
- axios.get(url[,config])
- axios.delete(url[,config])
- axios.head(url[,config])
- axios.post(url[,data[,config]])
- axios.put(url[,data[,config]])
- axios.patch(url[,data[,config]])
重点讲解axios(config)
//1.
axios({
//httpbin.org网站可以模拟传参
url:'httpbin.org',
//method:'可以指定请求类型(默认为get)'
method:'get'
//then是用来拿到res(结果)
}).then(res =>{
//打印结果
console.log(res);
})
//2.如果url中有参数
axios({
url:'http://123.111.32.32:8000/home/data?type=sell&page=3'
}).then(res => {
console.log(res);
})
//还有一种方法
axios({
url:'http://123.111.32.32:8000/home/data',
params: {
type:'pop'
page:'1'
}
}).then(res => {
console.log(res);
})
//3.
axios.get(url,对应的其他配置).then({
})