1. <!DOCTYPE html>
2. <html lang="en">
3. <head>
4. <meta charset="UTF-8">
5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
7. <title>Document</title>
8. </head>
9. <body>
10. <div id="app">
11. <input type="button" value="获取笑话" @click='getJoke'>
12. <p>{{mes}}</p>
13. </div>
14. <!-- 官网提供的axios在线地址 -->
15. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
16. <!--开发环境版本,包含了有帮助的命令行警告-->
17. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
18. <script>
19. /*
20. 接口:随机获取一条笑话
21. 请求地址:https://autumnfish.cn/api/joke
22. 请求方法:get
23. 请求参数:无
24. 响应内容:随机笑话
25. */
26. var app = new Vue({
27. el:'#app',
28. data:{
29. mes:'大家好,我是测试小白!'
30. },
31. methods:{
32. getJoke:function(){
33. var that = this;
34. axios.get('https://autumnfish.cn/api/joke').then(
35.
36. function(response){
37. console.log(response.data);
38. that.mes = response.data;
39. },
40. function(err){console.err}
41. )
42. }
43. }
44.
45. })
46.
47. </script>
48. </body>
49. </html>