【问题标题】:Create new row for every 3 items Vue.js为每 3 个项目 Vue.js 创建新行
【发布时间】:2021-04-14 22:37:48
【问题描述】:

基本上代码可以正常工作,但我无法更改元素的顺序。
目前结果如下:

但实际上我想要这样:

我的代码如下所示:

<template>
  <div class="home">
    <el-container>
      <el-row v-for="story of chunkedItems" :key="story.id">
        <el-col v-for="item of story" :key="item.id">
          <el-card>
            <div>{{ item.title }}</div>
            <div>{{ item.text }}</div>
          </el-card>
        </el-col>
      </el-row>
    </el-container>
  </div>
</template>

computed: {
    chunkedItems() {
      return this.$_.chunk(this.stories, 3);
    },
  },

欢迎提出任何建议。

【问题讨论】:

  • 也许可以通过 CSS el-container { display: flex; flex-direction: row; }

标签: javascript vue.js element-ui


【解决方案1】:

删除块并改用:span="8"

<template>
  <div class="home">
    <el-container>
      <el-row>
        <el-col :span="8" v-for="item of stories" :key="item.id">
          <el-card>
            <div>{{ item.title }}</div>
            <div>{{ item.text }}</div>
          </el-card>
        </el-col>
      </el-row>
    </el-container>
  </div>
</template>

computed: {
},

【讨论】:

  • 工作就像一个魅力。谢谢!显然我不太了解span 属性。
  • np, is in the docs 3/24 = 8,如果你想要像你的例子那样奇怪的列,使用模 :span="index % 2 == 0 ? 12:3" v-for="(item, index) in stories"
猜你喜欢
  • 1970-01-01
  • 2020-10-30
  • 2018-03-12
  • 1970-01-01
  • 2020-02-22
  • 1970-01-01
  • 2017-11-06
  • 2014-04-10
  • 2014-02-28
相关资源
最近更新 更多