img图片铺满父元素


引入多张尺寸不同的图片如果设置尺寸会导致图片变形

<div class="template_image">
       <img :src="$store.state.fileUploadUrl+item.thumb" alt="" />
</div>
.template_image{
        width: 100%;
        height: 170px;
        position:relative;
        overflow: hidden;
    }
    .template_image img{
        width: 100%;
        height: 170px;
        object-fit:cover;
    }

 2. 不固定图片宽高,按照比例显示

  npm install vue-proportion-directive --save

  import proportion from 'vue-proportion-directive'

  Vue.use(proportion)

<div v-proportion="0.5">
        比例0.5
</div>
<div class="template_image"  v-proportion="0.5625" :style="{'backgroundImage': `url(${$store.state.fileUploadUrl+item.cover})`}"></div>
.template_image {
    width: 100%;
    height: auto;
    background-size: cover;
    background-position: center center;
  }

or

<div class="template_image">
    <img v-proportion="0.75" :src="$store.state.fileUploadUrl+item.image" alt="" />
 </div>
.template_image img{
    object-fit: cover;
}

 

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM