欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue-resource ajax请求

程序员文章站 2022-03-06 13:12:29
...

``

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>vue-resource ajax请求</title>
  6. <script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
  7. <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
  8. </head>
  9. <body>
  10. <div id="box">
  11. <ol>
  12. <li v-for="site in sites">
  13. {{ site.name }}
  14. </li>
  15. </ol>
  16. </div>
  17. <script type = "text/javascript">
  18. window.onload = function(){
  19. var vm = new Vue({
  20. el:'#box',
  21. data:{
  22. sites: []
  23. },
  24. created: function () {
  25. //发送get请求
  26. this.$http.jsonp('https://www.test.com/index.php/api/v1/category').then(function(res){
  27. this.sites = res.body.data.son;
  28. },function(){
  29. console.log('请求失败处理');
  30. });
  31. }
  32. });
  33. }
  34. </script>
  35. </body>
  36. </html>``