vue根据浏览器窗口大小自适应排列多个div

javascript 复制代码
<template>
    <div class="bigBox">
        <div class="smallBox" :style="{'width':width}" v-for="item in 10" :key="item">
            <div class="contentItem">{{ item }}</div>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            width: '20%'
        };
    },
    created() {
        this.width = 100 / Math.trunc(window.innerWidth / 200) + '%';
        window.addEventListener('resize', this.reSizer);
    },
    destroyed() {
        window.removeEventListener('resize', this.reSizer);
    },
    methods: {
        reSizer() {
            this.width = 100 / Math.trunc(window.innerWidth / 200) + '%';
        }
    }
};
</script>

<style scoped lang="scss">
.bigBox {
    display: flex;
    flex-wrap: wrap;
    .smallBox {
        padding: 10px;
        .contentItem {
            height: 200px;
            border: 1px solid black;
        }
    }
}
</style>
相关推荐
馬致远几秒前
案例1- 跳动的心
javascript·css·css3
Hilaku2 分钟前
利用 link rel="prefetch":如何让用户的页面秒开?
前端·javascript·性能优化
youyu-youyu16 分钟前
h5 签名 vue
javascript·vue.js·ecmascript
没事多睡觉66622 分钟前
JavaScript 中 this 指向教程
开发语言·前端·javascript
asdfg125896330 分钟前
replace(/,/g, ‘‘);/\B(?=(\d{3})+(?!\d))/;千分位分隔
开发语言·前端·javascript
W***D45533 分钟前
nodejs链接redis
javascript·redis·bootstrap
梦65039 分钟前
VUE树形表格组件如何自定义展开箭头以及箭头位置
javascript·vue.js·elementui
国服第二切图仔42 分钟前
Electron for 鸿蒙PC项目开发之模态框组件
javascript·electron·harmonyos
_Jyann_44 分钟前
uniapp两种方式实现自定义tabbar
前端·javascript·uni-app
一 乐1 小时前
数码商城系统|电子|基于SprinBoot+vue的数码商城系统(源码+数据库+文档)
java·前端·javascript·数据库·vue.js·springboot