哈哈,久违了各位。我又回来了,最近在做毕设,所以难免会遇到很多问题,需要解决很多问题,在万能的博友帮助下,终于解决了Element-ui中轮播图的图片高度问题,话不多说上代码。

那个axios的使用不重要,大致思路就是页面渲染前拿到当前窗口的宽度*图片比例给轮播图一个初始的高度,当窗后大小发生变化时,监听事件里将轮播图高度重新赋值即可,再次感谢两位博友的帮助

<template>
<div v-if="imgurl">
<el-carousel :height="imgHeight+'px'" trigger="click">
<el-carousel-item v-for="(item,index) in imgurl" :key="index">
<img ref="image" style="width:100%;" :src="item" alt="轮播图" />
</el-carousel-item>
</el-carousel>
</div>
</template>
<script>
// 引入axios
import axios from "axios";
export default {
name: "First",
data() {
return {
imgurl: [],
imgHeight: ""
};
},
methods: {
imgLoad() {
this.$nextTick(function() {
// 获取窗口宽度*图片的比例,定义页面初始的轮播图高度
this.imgHeight = document.body.clientWidth*1/4
});
},
getImgUrl() {
axios
.get("/carousel")
.then(res => {
for (var i = 0; i < res.data.message.length; i++) {
const imgurl = `../../static/${res.data.message[i].imgurl}`;
this.imgurl.push(imgurl);
}
// 获取到图片后,调用this.imgLoad()方法定义图片初始高度
this.imgLoad();
})
.catch(error => {
console.log(error);
});
}
},
mounted() {
this.getImgUrl();
// 监听窗口变化,使得轮播图高度自适应图片高度
window.addEventListener("resize", () => {
this.imgHeight = this.$refs.image[0].height;
});
}
};
</script>

element-ui中轮播图自适应图片高度的更多相关文章

  1. Bootstrap中轮播图

    Bootstrap中轮播图插件叫作Carousel,为了清晰的表明每个标签在这里是什么意思,我把解释写在了下面的代码中. <!-- 以下容器就是整个轮播图组件的整体, 注意该盒子必须加上 cla ...

  2. jq demo 轮播图,图片可调用,向左,自动+鼠标点击切换

    <!doctype html> <html> <head> <meta http-equiv="Content-Type" content ...

  3. jq demo 轮播图,图片可调用,向上,自动+鼠标点击切换

    1 <!doctype html> <html> <head> <meta http-equiv="Content-Type" conte ...

  4. iview Carousel 轮播图自适应宽高;iview 轮播图 图片重叠问题;iview tabs 高度互相影响问题;vue this问题;

    最终效果图: 一.轮播图中图片自适应宽高:  <Carousel loop v-bind:height="imgHeight+'px'" v-model="caro ...

  5. javascript效果:手风琴、轮播图、图片滑动

    最近都没有更,就来几个效果充实一下. 都没有进行美化这步. 手风琴: 纯css: <!DOCTYPE html> <html lang="en"> < ...

  6. 【微信小程序】获取轮播图当前图片下标、滑动展示对应的位数、点击位数展示对应图片

    业务需求: 3个图片轮番播放,可以左右滑动,点击指示点可以切换图片  index.wxml: 这里使用小程序提供的<swiper>组件autoplay:自动播放interval:自动切换时 ...

  7. vue-cli中轮播图vue-awesome-swiper使用方法

    1 npm 安装 npm install vue-awesome-swiper --save 2在所用的组件中引入 import 'swiper/dist/css/swiper.css' import ...

  8. iOS中 轮播图放哪最合适? 技术分享

    我们知道,轮播图放在cell或collectionViewCell上会影响用户层级交互事件,并且实现起来比较麻烦,现在推出一个技术点:答题思路是:将UIScrollView放在UIView或UICol ...

  9. react-native-swiper设定高度的方法(设置rn轮播图所占高度)

    效果图: 直接上解决方案: 1.在Swiper标签外套一层View <View style={styles.container}> <Swiper style={styles.wra ...

随机推荐

  1. html5 模糊匹配搜索框

    使用bootstrap3-typeahead.js 文件在这里 引用: <script type="text/javascript" src="@Url.Conte ...

  2. 【转载】json 数据 添加 删除 排序

    张映 发表于 2014-02-10 分类目录: js/jquery 标签:json, 删除, 排序, 添加 js数据格式和json数据格式,各有各的用处,就个人而言,json更好用一点,js自身的数组 ...

  3. Have You Tried Delphi on Amazon Linux? (就是AWS用的Linux)

    The new Delphi Linux compiler enables customers to take new or existing Windows server applications ...

  4. foreach获取索引值

    List<" }; foreach (string item in items) { int index = items.IndexOf(item); Console.WriteLin ...

  5. 遍历所有的XML

    XmlElement rootElement = doc.DocumentElement; foreach (XmlElement childElement in rootElement) { //C ...

  6. matplotlib简介

    python的matplotlib包可以帮助我们绘制丰富的图表,有助于我们的数据分析. matplotlib官方文档:matplotlib 本博客所有代码默认导入matplotlib.pyplot和n ...

  7. JavaScript 数据实用程序库:Datalib

    Datalib 是一个 JavaScript 数据实用程序库. 快速使用Romanysoft LAB的技术实现 HTML 开发Mac OS App,并销售到苹果应用商店中.   <HTML开发M ...

  8. 什么水平算精通C++ Builder?

    主 题:   大家讨论一下什么水平算精通C++ Builder?(我这样算什么,马上要毕业了,不知道如何评价自己)         //C++ builder 使用时间3年 熟悉VCL源代码 开发过3 ...

  9. c# RedisHelper

    使用redis组件如下,至于为什么使用3.9版本,是因为4.0开始商业了,限制了次数 ServiceStack.Common" version="3.9.70"Servi ...

  10. Ansible的安装与使用初探

    一.环境准备 网络配置 管理端:192.168.237.201 受控端:192.168.237.202.192.168.237.203(一共2台) 硬件信息 CPU:1核 内存:512MB 磁盘:10 ...