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


     
    <!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>
  • 相关阅读:
    codeforces #601 div2 ABC~E1
    codeforces #600 div2 ABCD
    图形学 三次Hermite曲线绘制实现代码 javascript:es6+h5:canvas
    最小生成树(Prim / Kruskal)
    拓扑排序【Kahn算法(bfs)和dfs求拓扑序列及判环】
    Cow Traffic(正反向建图+DAG拓扑排序)
    JAVA大数
    【C/C++】关于strstr函数和c_str()函数
    【C/C++】关于函数调用传递实参
    2019上海icpc网络赛B. Light bulbs(思维+差分)
  • 原文地址:https://www.cnblogs.com/xianz666/p/14831418.html
Copyright © 2020-2023  润新知