axios基本用法
什么是axios?
Axios 是一个基于 promise 的网络请求库,可以用于浏览器和 node.js
axios的用法
<body>
<script src="./axios.min.js"></script>
<script>
/*
//发get请求,传参数
axios.get('./data.txt', {
params: {
id: 11,
}
}).then(res => {
console.log(res)
});
*/
/*
//发post请求,传参数
axios.post('./data.txt', {
username: '张三',
age: 18,
}).then(res => {
console.log(res)
});
*/
//配置参数发请求-get请求
axios({
method: 'get',
url: './data2.txt',
params: {
id: 12,
}
}).then(res => {
console.log(res);
})
//配置参数发请求-post请求
/*
axios({
method: 'post',
url: './data3.txt',
data: {
id: 12,
}
}).then(res => {
console.log(res);
})
*/
</script>
</body>
推荐阅读:
扫描二维码,在手机上阅读