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>
相关推荐
Dxy12393102169 小时前
JS DES 加密详解
开发语言·javascript·arcgis
充值内卷9 小时前
我给桌面加了个鱼缸:C++ 写后端,WebView2 里养一座 Three.js 小岛
开发语言·javascript·c++
椒哥11 小时前
一天被问几十次"允许",我统计了 517 次,然后写了个插件
前端·javascript·github
kyriewen12 小时前
我测了 6 种防请求竞态的写法:只有 1 种真能打
前端·javascript·程序员
OpsEye13 小时前
企业大模型压测,需要重点关注哪些指标?
javascript·ai编程
LuHang13 小时前
从天地图切换到高德地图:一次真实的底图迁移实战
前端·vue.js·cesium
像我这样帅的人丶你还14 小时前
我html生成的doc文档为何在手机文档显示不了图片?
前端·javascript
ruanno_top17 小时前
Vue 3 后台权限路由:我漏掉了按钮级裁剪,还把 403 写成了 404
vue.js
栉甜17 小时前
Vue2学习内容(上)
前端·javascript·vue.js·学习
java1234_小锋18 小时前
【技术专题】CSS3 网页技术 - CSS3 布局进阶
前端·css·css3