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 小时前
webpack编译中为什么不建议load替换ast中节点删除consolg.log
前端·javascript·webpack
源码获取_wx:Fegn08952 小时前
基于springboot + vue健身房管理系统
java·开发语言·前端·vue.js·spring boot·后端·spring
JIngJaneIL2 小时前
基于Java+ vue智慧医药系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
+VX:Fegn08953 小时前
计算机毕业设计|基于springboot + vue图书管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
阿蒙Amon3 小时前
JavaScript学习笔记:6.表达式和运算符
javascript·笔记·学习
小a杰.4 小时前
Flutter 设计系统构建指南
开发语言·javascript·ecmascript
三十_A6 小时前
如何正确实现圆角渐变边框?为什么 border-radius 对 border-image 不生效?
前端·css·css3
kgduu6 小时前
js之事件系统
javascript
jumu2026 小时前
3 次 B 样条优化:为你的 Matlab 程序加速
css
前端老宋Running6 小时前
“受控组件”的诅咒:为什么你需要 React Hook Form + Zod 来拯救你的键盘?
前端·javascript·react.js