您好,登录后才能下订单哦!
密码登录
            
            
            
            
        登录注册
            
            
            
        点击 登录注册 即表示同意《亿速云用户服务条款》
        这两天学习了vue如何从接口请求数据,所以,今天添加一点小笔记。
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>获取图片列表</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />    
  </head>
  <body>
    <div id="app">
      <ul>
        <li>
          <img v-for="imgItem in imgList" v-bind:src="imgItem.img" alt="" width="100%" height="100%"/>
        </li>
      </ul>
    </div>    
  </body>
  <script src="//cdn.bootcss.com/vue/2.1.0/vue.js" type="text/javascript" charset="utf-8"></script>
  <script src="//cdn.bootcss.com/vue-resource/1.0.3/vue-resource.js" type="text/javascript" charset="utf-8"></script>
  <script>
    var demo=new Vue({
      el:'#app',
      data: {
        imgList:[],
        getImgUrl: ''  //存数据接口        
      },
      created: function(){
        this.getImg()       //定义方法
      },
      methods: {
        getImg: function(){
          var that = this;    
          that.$http({      //调用接口
            method:'GET',
            url:this.getImgUrl //this指data
          }).then(function(response){ //接口返回数据
            this.imgList=response.data;             
          },function(error){
          })
        }
      }
    })
  </script>
</html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。