【vue】axios网络请求介绍
一、基础使用
1.引入js文件
2.在methods中的函数里写
axios.get(路径)
.then((res))=>{
console.log(res.data);//控制台打印结果数据
this.listArr=res.data//定义数组来接收返回来的数据
})
二、参数传递
参数传递一般在路径后面使用
params:{
num:2,//表示个数
page:3//表示页码
}
三、请求方式
axios({
method:"post",//默认get
url:"地址",
params:{//写参数
num:3,
page:4
}
}).then((res)=》{
console.log(res.data);
this.数组=res.data
}