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

<!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>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <div id="app">
        <input type="button" value="获取值" @click="getJoke">
        <p>{{xiaohua}}</p>

    </div>
    <script>
        var vu=new Vue({
            el:"#app",
            data:{
                xiaohua:"很好笑"

            },
            methods:{
                getJoke:function(){
                    var that=this;
                    axios.get("https://autumnfish.cn/api/joke").then(function(res){
                        console.log(res)
                        that.xiaohua=res.data;
                    },function(err){
                        console.log(err)
                    })
                }
            }
        })
    </script>
    
</body>
</html>

  

posted @ 2021-05-31 15:35  红尘沙漏  阅读(203)  评论(0编辑  收藏  举报