element-ui中轮播图自适应图片高度
哈哈,久违了各位。我又回来了,最近在做毕设,所以难免会遇到很多问题,需要解决很多问题,在万能的博友帮助下,终于解决了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中轮播图自适应图片高度的更多相关文章
- Bootstrap中轮播图
Bootstrap中轮播图插件叫作Carousel,为了清晰的表明每个标签在这里是什么意思,我把解释写在了下面的代码中. <!-- 以下容器就是整个轮播图组件的整体, 注意该盒子必须加上 cla ...
- jq demo 轮播图,图片可调用,向左,自动+鼠标点击切换
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content ...
- jq demo 轮播图,图片可调用,向上,自动+鼠标点击切换
1 <!doctype html> <html> <head> <meta http-equiv="Content-Type" conte ...
- iview Carousel 轮播图自适应宽高;iview 轮播图 图片重叠问题;iview tabs 高度互相影响问题;vue this问题;
最终效果图: 一.轮播图中图片自适应宽高: <Carousel loop v-bind:height="imgHeight+'px'" v-model="caro ...
- javascript效果:手风琴、轮播图、图片滑动
最近都没有更,就来几个效果充实一下. 都没有进行美化这步. 手风琴: 纯css: <!DOCTYPE html> <html lang="en"> < ...
- 【微信小程序】获取轮播图当前图片下标、滑动展示对应的位数、点击位数展示对应图片
业务需求: 3个图片轮番播放,可以左右滑动,点击指示点可以切换图片 index.wxml: 这里使用小程序提供的<swiper>组件autoplay:自动播放interval:自动切换时 ...
- vue-cli中轮播图vue-awesome-swiper使用方法
1 npm 安装 npm install vue-awesome-swiper --save 2在所用的组件中引入 import 'swiper/dist/css/swiper.css' import ...
- iOS中 轮播图放哪最合适? 技术分享
我们知道,轮播图放在cell或collectionViewCell上会影响用户层级交互事件,并且实现起来比较麻烦,现在推出一个技术点:答题思路是:将UIScrollView放在UIView或UICol ...
- react-native-swiper设定高度的方法(设置rn轮播图所占高度)
效果图: 直接上解决方案: 1.在Swiper标签外套一层View <View style={styles.container}> <Swiper style={styles.wra ...
随机推荐
- XF 表视图添加和删除行
using System;using Xamarin.Forms;using Xamarin.Forms.Xaml; [assembly: XamlCompilation (XamlCompilati ...
- x:ArrayExtension
<Window.Resources> <x:ArrayExtension x:Key="array" Type="{x:Type sys:Int32}& ...
- JS超链接动态显示图片
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- WPF支持OneWay,TwoWay,OneTime,Default和OneWayToSource
原文:WPF支持OneWay,TwoWay,OneTime,Default和OneWayToSource 无论是目标属性还是源属性,只要发生了更改,TwoWay 就会更新目标属性或源属性. OneWa ...
- ASP.NET MVC 学习笔记1 Talk about controller & route
For the sake of learning programming better, I'd like to increase the frequency of using English. So ...
- PHP的MIPS交叉编译(CC=mipsel-openwrt-linux-uclibc-gcc,LD=mipsel-openwrt-linux-uclibc-ld)
物联网内存吃紧,跑JVM这种内存大户肯定吃不消.要跑还是跑C实现的服务,比如Nginx+PHP+SQLite.比如一些家用无线路由器,系统是Linux发行版OpenWrt,内存只有64MB到128MB ...
- Java HashMap实现原理 源码剖析
HashMap是基于哈希表的Map接口实现,提供了所有可选的映射操作,并允许使用null值和null建,不同步且不保证映射顺序.下面记录一下研究HashMap实现原理. HashMap内部存储 在Ha ...
- visual studio 2017 添加MSDN
原文:visual studio 2017 添加MSDN 1.启动VS2017的安装软件,点击更改,进行MSDN帮助组件添加安装. 2.在单个组件中找到"Help Viewer", ...
- Windows Mount NFS Share from e.g. Linux
Note: Not Stable, so steps below are for reference only ************ Linux Configuration NFS Share 1 ...
- C#调用记事本并填写内容
using System.Runtime.InteropServices; using System.Diagnostics; [DllImport("User32.DLL") ...