Axios入门
1.引入Axios的js文件
<script src="js/axios-0.18.0.js"></script>
Axios
请求方式别名:
axios.get(url[,config])
axios.delete(url[,config])
axios.post(url[,data[,config]])
axios.put(url[,data[,config]])
发送GET/POST请求
axios.get("https://mock.apifox.cn/m1/3128855-0-default/emp/list").then(result => {
console.log(result.data)
});
axios.post("https://mock.apifox.cn/m1/3128855-0-default/emp/deleteById","id=1").then(result => {
console.log(result.data)
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ajax-Axios</title>
<script src="js/axios.js"></script>
</head>
<!--
Axios
请求方式别名
axios.get(url[,config])
axios.delete(url[,config])
axios.post(url[,data[,config]])
axios.put(url[,data[,config]])
发送GET请求
axios.get("https://mock.apifox.cn/m1/3128855-0-default/emp/list").then(result => {
console.log(result.data)
});
axios.post("https://mock.apifox.cn/m1/3128855-0-default/emp/deleteById","id=1").then(result => {
console.log(result.data)
});
-->
<body>
<input type="button" value="获取数据GET" onclick="get()">
<input type="button" value="删除数据POST" onclick="post()">
</body>
<script>
function get(){
/* axios({
method:"get",
url:"https://mock.apifox.cn/m1/3128855-0-default/emp/list",
}).then(result => {
console.log(result.data)
}) */
axios.get("https://mock.apifox.cn/m1/3128855-0-default/emp/list").then(result => {
console.log(result.data)
});
}
function post(){
/* axios({
method:"post",
url:"https://mock.apifox.cn/m1/3128855-0-default/emp/deleteById",
data:"id=1" 请求参数
}).then(result => {
console.log(result.data)
}) */
axios.post("https://mock.apifox.cn/m1/3128855-0-default/emp/deleteById","id=1").then(result => {
console.log(result.data)
});
}
</script>
</html>