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;
        }
相关推荐
明月_清风1 小时前
自定义右键菜单:在项目里实现“选中文字即刻生成新提示”
前端·javascript
明月_清风1 小时前
告别后端转换:高质量批量导出实战
前端·javascript
刘发财5 小时前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github
牛奶8 小时前
2026年大模型怎么选?前端人实用对比
前端·人工智能·ai编程
牛奶8 小时前
前端人为什么要学AI?
前端·人工智能·ai编程
Kagol10 小时前
🎉OpenTiny NEXT-SDK 重磅发布:四步把你的前端应用变成智能应用!
前端·开源·agent
GIS之路11 小时前
ArcGIS Pro 中的 notebook 初识
前端
JavaGuide12 小时前
7 道 RAG 基础概念知识点/面试题总结
前端·后端
ssshooter12 小时前
看完就懂 useSyncExternalStore
前端·javascript·react.js
格砸13 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端