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>
相关推荐
23级二本计科1 分钟前
前端 HTML + CSS + JavaScript
前端·css·html
大鸡爪12 分钟前
基于PDF.js的安全PDF预览组件实现:从虚拟滚动到水印渲染
vue.js
HashTang15 分钟前
买了专业屏只当普通屏用?解锁 BenQ RD280U 的“隐藏”开发者模式
前端·javascript·后端
мо仙堡杠把子ご灬15 分钟前
【无标题】
javascript
myltx17 分钟前
node-sass 迁移 sass(dart-sass) 后样式报错?用 loader 先把构建救回来
vue.js·前端工程化
用户02033886131418 分钟前
Vue以及ElementPlus学习
vue.js
用户8417948145620 分钟前
vxe-table 个性化列自定义列弹出层修改高度、修改最大高度不自动适应表格高度的方法
vue.js
xuedaobian20 分钟前
Markdown 宽表格突破容器边界滚动方案
前端·css
董世昌4122 分钟前
js遍历数组和对象的常用方法有哪些?
开发语言·javascript·ecmascript
小oo呆33 分钟前
【学习心得】Python的Pydantic(简介)
前端·javascript·python