css绘制s型(grid)

在之前有通过flex布局实现了s型布局,是通过截取数组形式循环加载数据

这次使用grid直接加载数据通过css实现

html 复制代码
<div id="app">
    <template v-for="(item,inx) in items">
        <div class="row">
            <template v-for="(ite, index) in item.arr">
                <div class="row-list" :style="setEvent(index)">
                    <div class="lineBg">
                        <div class="line-title">
                            <div class="box">{{ ite }}</div>
                        </div>
                    </div>
                </div>
            </template>
        </div>
    </template>
</div>
js 复制代码
 new Vue({
        el: '#app',
        computed: {
            setEvent() {
                return function (index) {
                    // 通过下标得当前是第几行
                    const row = Math.floor(index / this.row) + 1;
                    // 当前行的第几个
                    const rowIndex = index % this.row;
                    if (this.evenRow(index)) {
                        return {
                           // 设置grid属性值
                            gridRowStart: row,
                            gridColumnStart: this.row - rowIndex
                        }
                    }
                }
            },
        },
        data: {
            row: 6,
            items: [
                {
                    arr: [1, 2, 3, 4, 5, 6]
                },
                {
                    arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
                },
                {
                    arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
                },
                {
                    arr: [1, 2, 3, 4]
                }
            ],
        },
    })
css 复制代码
        .row {
            display: grid;
            grid-template-columns: repeat(6, 1fr);
            grid-template-rows: minmax(50px, auto);
            grid-auto-rows: minmax(50px, auto);
            grid-gap: 10px;
            margin-bottom: 10px;
            text-align: center;
        }

        .row-list {
            border: 1px solid #cccccc;
        }
相关推荐
F***c32520 小时前
React自然语言处理应用
前端·react.js·自然语言处理
1***Q78420 小时前
React项目
前端·javascript·react.js
幸福专买店20 小时前
【Flutter】flutter 中 包裹内容显示 的设置方式
前端·javascript·flutter
和和和21 小时前
🗣️面试官: 那些常见的前端面试场景问题
前端·javascript·面试
lxp19974121 小时前
vue笔记摘要-更新中
前端·vue.js·笔记
Oriental21 小时前
URL解码踩坑记录
前端·后端
San3021 小时前
ES6+ 新特性解析:让 JavaScript 开发更优雅高效
前端·javascript·ecmascript 6
Heo21 小时前
简单聊聊webpack摇树的原理
前端·javascript·面试
少卿21 小时前
React 日历组件完全指南:从网格生成到农历转换
前端·react.js
程序员鱼皮21 小时前
Gemini 3.0 发布!
前端·ai编程·gemini