首页 > 移动平台 > 详细

vue.js中get和post请求使用 axios

时间:2021-05-31 15:44:58      阅读:11      评论:0      收藏:0      [点我收藏+]
技术分享图片

 

 

 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--<script src="./vue.js"></script>-->
   
</head>
<body>
    <input type="button" value="get请求" class="get">
    <input type="button" value="post请求" class="post">
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        document.querySelector(".get").onclick=function(){
                axios.get("https://autumnfish.cn/api/joke/list?num=3").then(function(response){
                    console.log(response)
                },
                function(err){
                    console.log("err")
                }
            )
        }
        document.querySelector(".post").onclick=function(){
            axios.post("https://autumnfish.cn/api/user/reg",{"username":"jim"}).then(function(response){
                console.log(response)
                let homeObj = JSON.stringify(response);
                console.log("post请求结果=="+homeObj);
                console.log(response.data+response.status)
            })
        }
        


    </script>
    
</body>
</html>

vue.js中get和post请求使用 axios

原文:https://www.cnblogs.com/xianz666/p/14831418.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!