使用ant-design中Carousel加载多个iframe的优化方法

发布时间:2020-05-26 09:48:53 作者:Leah
来源:亿速云 阅读:1436

今天小编给大家分享的是使用ant-design中Carousel加载多个iframe的优化方法。小编觉得挺实用的,为此分享给大家做个参考。一起跟随小编过来看看吧。

项目中遇到用ant-design 的 Carousel 加载很多个iframe,因为一次生成很多iframe,会使浏览器很慢
思路:只在当先显示的项里面加载iframe,其余的都默认加载一个截图,再切换之前用beforeChange改变 变量idx,把即将要显示的内容由图片变成视频
代码如下

<template>
  <div class="morevideowarp">
    <template v-if="!hasvideo">
      <a-carousel :afterChange="afterChange" :beforeChange="beforeChange" arrows dotsClass="slick-dots slick-thumb scrollDivNew">
        <!-- 下面的缩略图 -->
        <a slot="customPaging" slot-scope="props">
          <img :src="videoProList[props.i].picUrl" />
        </a>
        <!-- 向左的箭头 -->
        <div
          slot="prevArrow"
          slot-scope="props"
          class="custom-slick-arrow"
          
        >
          <a-icon type="left-circle" />
        </div>
        <!-- 向右的箭头 -->
        <div slot="nextArrow" slot-scope="props" class="custom-slick-arrow" >
          <a-icon type="right-circle" />
        </div>
        <!-- 主体部分 -->
        <div v-for="(item,index) in videoProList" :key="index">
                     <!-- 利用idx与index是否相等,决定渲染的是iframe或者img -->
          <template v-if="idx===index"><iframe :src="videoUrl(item)"></iframe></template>
          <template v-else><img :src="item.picUrl" /></template>
        </div>
      </a-carousel>
    </template>
    <div v-else class="noresult">暂无视频</div>
  </div>
</template>

js逻辑部分

methods: {
    beforeChange (from, to) {
      // 切换之前把变量idx变成即将要显示的那个项的idx,这样渲染的时候就会渲染iframe,而旧的也会销毁
      this.idx = to
    }
  }

以上就是使用ant-design中Carousel加载多个iframe的优化方法,代码示例简单明了,如果在日常工作遇到此问题。通过这篇文章,希望你能有所收获,更多详情敬请关注亿速云行业资讯频道!

推荐阅读:
  1. owl carousel来回重复使用多次的方法
  2. js加载或更新父页面的iframe

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ant-design carousel iframe

上一篇:测试思科ios路由器是否具备一致性哈希的功能

下一篇:mysql常用到的几个命令

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》