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;
        }
相关推荐
前端小崔几秒前
前端面试题之ES6保姆级教程
开发语言·前端·javascript·面试·职场和发展·ecmascript·es6
Bug从此不上门9 分钟前
【无标题】
前端·javascript·uni-app·vue
HarderCoder10 分钟前
ByAI:Redux中间件的原理和ts简化实现
前端·redux
贩卖纯净水.13 分钟前
Webpack依赖
前端·webpack·node.js
crary,记忆14 分钟前
微前端 - Module Federation使用完整示例
前端·react·angular
不知几秋20 分钟前
Spring Boot
java·前端·spring boot
程序猿ZhangSir24 分钟前
Vue3 项目的基本架构解读
前端·javascript·vue.js
HarderCoder28 分钟前
ByAI: Redux的typescript简化实现
前端
90后的晨仔36 分钟前
RxSwift 框架解析
前端·ios
我命由我1234541 分钟前
VSCode - VSCode 放大与缩小代码
前端·ide·windows·vscode·前端框架·编辑器·软件工具