<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<title>Document</title>
</head>
<body>
<div id="app">
<button>发送get请求</button>
<button>发送post请求</button>
<button>发送put请求</button>
<button>发送delete请求</button>
</div>
</body>
<script>
const btn = document.querySelectorAll("button")
axios({
method: "GET/POST",
url: '/user/12345',
data: {
name: "lisi",
age: 17,
},
baseURL: "",
headers: { 'X-Requested-With': 'XMLHttpRequest' },
params: {
ID: 12345
},
timeout: 1000,
})
axios.request(config)
axios.get(url, [config])
axios.delete(url, [config])
axios.head(url, [config])
axios.options(url, [config])
axios.post(url, [data, [config]])
axios.put(url, [, data, [config]])
axios.patch(url, [, data, [config]])
btn[0].onclick = function () {
axios.request({
method: "GET",
url: "https://api.it120.cc/conner/shop/goods/category/all"
}).then(response => {
console.log(response)
})
}
btn[1].onclick = function () {
axios.post(
"https://api.it120.cc/conner/shop/goods/category/all",
{
}).then(response => {
console.log(response)
})
}
axios.defaults.baseURL = 'https://api.example.com';
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
const axi = axios.create({
baseURL: "https://api.it120.cc/conner",
headers: {"xx": "xxxx"},
})
axi.post("/shop/goods/category/all",{data: {name: "lisi"}}).then(response=>{
console.log(response)
})
const axis = axios.create({
baseURL: "https://api.it120.cc/conner",
})
axis.get("/shop/goods/category/all").then(response=>{
console.log(response)
})
</script>
</html>