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>
相关推荐
小李子呢02115 小时前
前端八股CSS(2)---动画的实现方式
前端·javascript
布局呆星7 小时前
Vue3 | 组件通信学习小结
前端·vue.js
竹林81810 小时前
RainbowKit 快速集成多链钱包连接:从“连不上”到丝滑切换的踩坑实录
前端·javascript
Ruihong10 小时前
你的 Vue 3 reactive(),VuReact 会编译成什么样的 React?
vue.js·面试
Ruihong10 小时前
你的 Vue 3 ref(),VuReact 会编译成什么样的 React?
vue.js·面试
一 乐10 小时前
酒店预订|基于springboot + vue酒店预订系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·酒店预订系统
慕斯fuafua10 小时前
CSS——盒模型
前端·css
嗜好ya10 小时前
解决 Vite 项目中 import.meta.env 变量为 undefined 的问题
前端·javascript·vue.js
心连欣10 小时前
JS算法入门:图解“冒泡排序”,彻底搞懂双重循环的奥义
前端·javascript