axios请求数据.html 928 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <title>axios 获取数据</title>
  7. <meta name="description" content="">
  8. <meta name="keywords" content="">
  9. <link href="" rel="stylesheet">
  10. </head>
  11. <body>
  12. <div id="app">
  13. <button @click='getAjaxInfo()'>按钮</button>
  14. <span> {{msg}}</span>
  15. </div>
  16. <script type="text/javascript" src='../js/vue.min.js'></script>
  17. <script type="text/javascript" src='../js/axios.min.js'></script>
  18. <script type="text/javascript">
  19. //没有后台数据,所以会报错
  20. var app = new Vue({
  21. el: '#app',
  22. data: {
  23. msg: '我是数据'
  24. },
  25. methods: {
  26. getAjaxInfo: function() {
  27. axios('ajax_info.txt').then(function(res) {
  28. this.msg = res.data;
  29. }.bind(this)).catch(function(err) {
  30. console.log(err);
  31. })
  32. }
  33. }
  34. });
  35. </script>
  36. </body>
  37. </html>