1、安装axios
在cmd或powershell打开文件后,输入下面的命令
可在项目框架中的package.json中查看是否:
二、引用axios
import axios from 'axios'
在需要使用的页面中引用
三、get方式使用
axios({
url: "", // url
params: {
// 参数
name: xxx,
age: xxx,
},
})
.then(function (res) {
console.log(res); // 成功回调
})
.catch(function (err) {
console.log(err); // 失败回调
});
四、post请求
五、qs配置
引入方法:
import axios from 'axios'
import qs from 'qs'
写法:
axios({
method: "post", //请求方式
url: "", //url
data: qs.stringify({
// 参数
}),
})
.then(function (res) {
console.log(res); //成功回调
})
.catch(function (err) {
console.log(err); //失败回调
});