获取图片大小
<template>
<div class="about-page">
<el-carousel height="700px" :interval="3000" arrow="always">
<el-carousel-item v-for="(item, index) in imgs" :key="index">
<img :src="item.imgUrl" alt="">
</el-carousel-item>
</el-carousel>
</div>
</template>
<script>
export default {
data() {
return {
aa: ' https://14234929.s61i.faiusr.com/2/AD0IserkBhACGAAg1e2RywUo0--goQUwgA840AU.jpg',
imgInfo: {},
imgs:[
{
imgUrl: require('../../assets/img/x.jpg')
},
{
imgUrl: require('../../assets/img/z.jpg')
}
]
};
},
methods: {
getImgInfo () {
let img = new Image()
img.src = this.aa
const vm = this
img.onload = function () {
vm.$set(vm.imgInfo, 'width', img.width)
vm.$set(vm.imgInfo, 'height', img.height)
console.log(vm.imgInfo) // 打印图片信息
}
}
},
created () {
this.getImgInfo()
},
}
</script>
<style scoped lang="less">
// fill|contain|cover|scale-down|none|initial|inherit;
.about-page{
height: 1000px;
}
// 轮播图
.el-carousel__item img {
object-fit: cover;
margin: 0;
width: 100%;
height: 100%;
}
.el-carousel__item:nth-child(2n) {
background-color: #99a9bf;
}
.el-carousel__item:nth-child(2n+1) {
background-color: #d3dce6;
}
</style>
本文来自博客园,作者:zjxgdq,转载请注明原文链接:https://www.cnblogs.com/zjxzhj/p/14984826.html

浙公网安备 33010602011771号