vue使用element ui 的走马灯 时候 ,出现的图片闪烁问题

1.问题描述:
在使用element 走马灯时,请求接口里面的图片,鼠标第一次移上去图片会一闪而过。

2.解决:
节点上加个ref在这里插入图片描述
然后用定时器
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现Vue使用Element-ui走马灯功能动态改变图片和容器大小,可以按照以下步骤进行: 1. 在Vue中引入Element-ui的Carousel组件,并在template中使用。 2. 在data中定义图片列表和容器大小。 3. 在mounted生命周期中获取容器的宽度,以便动态调整图片大小。 4. 在methods中定义一个函数,用于动态改变容器大小。 5. 在template中使用v-bind指令将容器大小绑定到Carousel组件上,并使用v-for指令循环渲染图片。 下面是示例代码: ``` <template> <el-carousel :height="containerHeight"> <el-carousel-item v-for="(item, index) in imgList" :key="index"> <img :src="item.src" :style="{ width: imgWidth + 'px', height: imgHeight + 'px' }"> </el-carousel-item> </el-carousel> </template> <script> export default { data() { return { imgList: [ { src: 'https://xxx.com/1.jpg' }, { src: 'https://xxx.com/2.jpg' }, { src: 'https://xxx.com/3.jpg' }, ], containerWidth: 0, containerHeight: 300, // 初始化高度,可根据需求设置 imgWidth: 0, imgHeight: 0, } }, mounted() { this.containerWidth = this.$el.clientWidth this.setImgSize() window.addEventListener('resize', this.setImgSize) }, beforeDestroy() { window.removeEventListener('resize', this.setImgSize) }, methods: { setImgSize() { this.containerWidth = this.$el.clientWidth this.imgWidth = this.containerWidth this.imgHeight = this.containerHeight }, }, } </script> ``` 在上面的代码中,我们使用了v-bind指令将容器高度绑定到Carousel组件上,并使用v-for指令循环渲染了图片。在mounted生命周期中,我们获取了容器的宽度,并在setImgSize函数中动态调整了图片的大小。同时,我们还添加了一个resize事件监听器,以便在窗口大小改变时重新计算图片大小。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值