如何用Vue.js获取api数据

如何用Vue.js获取api数据_第1张图片

下面是一个轮播图,效果如上,需要用到swiper插件

需要用到的插件有:

   
   
   
   

   

   
   
   
   
   


HTML:


   
container">
       
swiper-container">
           
swiper-wrapper" id="swiper-wrapper">
               
               
swiper-slide" v-for="rolling inrollings">
                       //注:f_siUrl是图片的路径
               

           

           
           
swiper-pagination">

       

   



Vue.js代码

//轮播图
    var vm = new Vue({
        el: "#swiper-wrapper",
        data: {
            rollings: {}
        },
        mounted: function () {
            this.$nextTick(function () {
                this.$http.jsonp('http://thanbach.com/YXShoppingMallApp/exclusiveShop_getExclusiveShopSlide.jhtml?f_sId=2968d399-4402-4baf-b407-2b329f2a2c02').then(function (res) {
//                    alert(res.data.rows.length);
                    vm.rollings = res.data.rows;
                    Vue.nextTick(function () {
                        var swiper = new Swiper('.swiper-container', {
                            pagination: '.swiper-pagination',
                            autoplay: 3000,   //间隔3秒执行一次
                            autoplayDisableOnInteraction: false,   //鼠标悬停不停止滚动
                            loop: true     //循环滚动
                        });
                    });




                })
            })
        }
    });




你可能感兴趣的:(web前端)