• vue加载图标实现loading组件


    当图片还没加载完成时,可以通过loading组件填充空白区

    效果图

    components/loading/index.vue

    <template>
        <div class="mine-loading" :class="{'me-loading-inline':inline}">
            <span class="mine-loading-indicator">
                <img src="./loading.gif">
            </span>
            <span class="mine-loading-text" v-if="loadingText">{{loadingText}}</span>
        </div>
    </template>
    
    <script>
    export default {
       name:"MeLoading",
       props:{//过滤器
            inline:{
                type:Boolean,
                default:false
            }
       },
       data(){
           return{
               loadingText:"加载中..."
           }
       }
    }
    </script>
    
    <style lang="scss" scoped>
    
        .mine-loading{
            100%;
            height:100%;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
    
            //图文左右排列时
            &.me-loading-inline{
                flex-direction: row;
               
                .mine-loading-indicator ~ .mine-loading-text{
                    margin-top:0px;
                    margin-left:7px;
                }
            }
    
            // 存在.mine-loading-indicator和.mine-loading-text时
            .mine-loading-indicator ~ .mine-loading-text{
                margin-top:7px;
            }
        }
    </style>

    记得loading.gif也丢到这个目录里

    src/components/slider/index.vue

    <template>
      <div class="slider-wrap">
        <me-loading v-if="!sliders.length" />
        <swiper ref="mySwiper" :options="swiperOptions">
          <swiper-slide v-for="(slider,index) in sliders" :key="index">
              <a :href="slider.linkUrl">
                  <img :src="slider.picUrl">
              </a>
          </swiper-slide>
          <div class="swiper-pagination" slot="pagination" v-if="sliders.length"></div>
          <div class="swiper-button-prev" slot="button-prev" v-if="sliders.length"></div>
          <div class="swiper-button-next" slot="button-next" v-if="sliders.length"></div>
        </swiper>
      </div>
    </template>
    
    <script>
    import { Swiper, SwiperSlide } from 'vue-awesome-swiper';
    import 'swiper/css/swiper.css';
    import { getSliders } from 'api/slider';
    import MeLoading from 'components/loading';
     
    export default {
        name:"Slider",
        title: 'Autoplay',
        components:{
            Swiper,
            SwiperSlide,
            MeLoading
        },
        data() {
          return {
            sliders:[],
            swiperOptions: {
              spaceBetween: 30,
              centeredSlides: true,
              autoplay: {
                delay: 2500,
                disableOnInteraction: false
              },
              loop: true,
              pagination: {
                el: '.swiper-pagination',
                clickable: true
              },
              navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev'
              }
            }
          }
        },
        created(){
            //一般在created里获取远程数据
            this.getSliders();    
        },
        computed: {
          swiper() {
            return this.$refs.mySwiper.$swiper;
          }
        },
        mounted() {
          //console.log('Current Swiper instance object', this.swiper);
          this.swiper.slideTo(3, 1000, false);
        },
        methods:{
            getSliders(){
                return getSliders().then(data=>{
                    //console.log(data);
                    this.sliders=data;
                    
                });
            }
        }
      }
    </script>
    
    <style lang="scss" scoped>
        .swiper-container{
            100%;
            height:180px;
        }
        .slider-wrap{
          height:180px;
        }
        .swiper-slide a{
            display:block;
            100%;
            height:100%;
    
            & img{
                100%;
                height:100%;
            }
        }
    </style>
  • 相关阅读:
    ubuntu重复登录问题
    CUDA相关问题
    pytorch安装(使用pip3装到conda环境下)
    ubuntu16.04 anaconda的安装和卸载
    vscode插件安装失败的解决方案
    使用ffmpeg进行视频截图
    Spring加载早期获取BasePackage
    chrome最耐看的主题
    针对MySQL的MVCC多版本并发控制的一些总结
    docker创建mysql容器,并挂载数据+配置
  • 原文地址:https://www.cnblogs.com/chenyingying0/p/12640107.html
Copyright © 2020-2023  润新知