ASCII码 ASCII码

vue-resource ajax请求

发布于:2022-02-09 10:55:01  栏目:技术文档

``

  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>``
相关推荐
阅读 +