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;
        }
相关推荐
狂野小青年2 分钟前
npm 报错 gyp verb `which` failed Error: not found: python2 解决方案
前端·npm·node.js
鲁鲁5176 分钟前
Windows 环境下安装 Node 和 npm
前端·npm·node.js
跑调却靠谱24 分钟前
elementUI调整滚动条高度后与固定列冲突问题解决
前端·vue.js·elementui
呵呵哒( ̄▽ ̄)"42 分钟前
React - 编写选择礼物组件
前端·javascript·react.js
Coding的叶子1 小时前
React Flow 简介:构建交互式流程图的最佳工具
前端·react.js·流程图·fgai·react agent
apcipot_rain6 小时前
【应用密码学】实验五 公钥密码2——ECC
前端·数据库·python
ShallowLin6 小时前
vue3学习——组合式 API:生命周期钩子
前端·javascript·vue.js
Nejosi_念旧6 小时前
Vue API 、element-plus自动导入插件
前端·javascript·vue.js
互联网搬砖老肖6 小时前
Web 架构之攻击应急方案
前端·架构
pixle07 小时前
Vue3 Echarts 3D饼图(3D环形图)实现讲解附带源码
前端·3d·echarts