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>