首先 axios 是一个http的库,所以要在nodejs 和浏览器中
在服务器中运行玩,就要先在本地配置phpStudy wamp 等一些虚拟的服务
然后配合vue 本地 就可以玩了
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="box">
{{mes}}
<input type="submit" value="get请求" @click="get">
<input type="submit" value="post请求" @click="post1">
</div>
<script>
var vm = new Vue({
el:'#box',
data:{
mes:"大家好"
},
methods:{
get:function(){
axios.get('./user/data.php')
.then(function(response){
console.log(response);
})
.catch(function(error){
console.log(error)
})
},
post1:function(){
axios.post('./user/post.php',{
name:'zmq',
password:'123'
})
.then(function(res){
console.log(res)
})
.catch(function(error){
console.log(error)
})
}
}
})
</script>
</body>
</html>
get () post () 中的文件时自己创建的两个很基础的php文件 ,post请求,php中需要接收一下post传的参数

然后就ok了,一开始很懵逼,也找不到适合自己这个菜鸟学习的手册讲的更详细一些的东西
axios的并发请求
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="box">
{{mes}}
<input type="submit" value="get多请求" @click="get">
</div>
<script>
var vm = new Vue({
el:'#box',
data:{
mes:"大家好"
},
methods:{
get:function(){
function getUserAccount(){
return axios.get('./user/data.php');
}
function getUserPermissions(){
return axios.get('./user/data1.php');
}
axios.all([getUserAccount(),getUserPermissions()])
.then(axios.spread(function(acct,perms){
//然后两个并发请求就执行了
}))
}
}
})
</script>
</body>
</html>
执行结果

这样就成功了
这些年,我们经历了多轮的淘汰赛,每轮淘汰赛都面临不同的对手,但每轮淘汰赛中我们都发展了.
浙公网安备 33010602011771号