img图片铺满父元素


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

.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)

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

or

.template_image img{ object-fit: cover; }

相关