ajax.html 913 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  8. <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
  9. <link href="../css/style.css" rel="stylesheet"> </head>
  10. <body>
  11. <div id="myApp">
  12. <input type="button" @click="get()" value="点我异步获取数据(Get)">
  13. </div>
  14. <script>
  15. var vm = new Vue({
  16. el: '#myApp',
  17. data: {
  18. msg: 'Hello World!',
  19. },
  20. methods: {
  21. get: function() {
  22. //发送get请求
  23. var data = {
  24. a: 1,
  25. b: 2
  26. };
  27. this.$http.get('ajax_info.txt', data).then(function(res) {
  28. document.write(res.body);
  29. }, function() {
  30. console.log('请求失败处理');
  31. });
  32. }
  33. }
  34. });
  35. </script>
  36. </body>
  37. </html>