在Bootstrap 4

时间:2018-03-27 09:42:01

标签: vue.js vuejs2 bootstrap-4 v-for

任何人都可以通过bootstrap-4中的vue-js通过3列布局帮助我。我希望我的复选框显示为3列。用户是有序的,我希望订单从第一列开始,然后是第二列,最后是第三列。

<div v-for="(user, index) in users">
  <div class="{'controls' : (index % (users.length/3)===0)}">
    <input type="checkbox" :id="'user_'+user.id" :value="user.id" class="form-check-input" v-model="form.checkedUsers">
    <label class="form-check-label" for="'user_'+userr.id">
      <img :src="user.photo_url" class="small-photo mx-2"> @{{ user.first_name }} @{{ user.last_name }}
    </label>
  </div>
</div>

由于

1 个答案:

答案 0 :(得分:3)

使用Vue方法使用数组&#34; chunk&#34;将项目分组为3组。方法。使用嵌套的v-for重复组,然后使用每个组中的项目。这将把它们放在3列中 top-to-bottom ...

Vue2控制器:

  methods: {
    chunk: function(arr, size) {
      var newArr = [];
      for (var i=0; i<arr.length; i+=size) {
        newArr.push(arr.slice(i, i+size));
      }
      this.groupedItems  = newArr;
    }
  },

标记:

<div class="container" id="app">
    <div class="row">
        <div class="col-sm-4 py-2" v-for='(g, gIndex) in groupedItems'>
            <form class="form-inline" v-for='(item, index) in g'>
                <div class="form-check">
                    <input class="form-check-input" type="checkbox">
                    <label class="form-check-label">
                     {{ item.name }}
                    </label>
                </div>
            </form>
        </div>
    </div>
</div>

演示: https://www.codeply.com/go/ZaiUsUupsr

备用选项是将它们放在3列中,而不是在循环中每3个项目重新迭代.row。所有复选框都可以放在一个row中,它们将在3列中排序从左到右

演示: https://www.codeply.com/go/3gOvXFzaOw

<div class="container">
    <div class="row">
        <div v-for="item in items" class="col-sm-4 py-2">
            <form class="form-inline">
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" >
                    <label class="form-check-label">
                        {{ item.name }}
                    </label>
                </div>
            </form>
        </div>
    </div>
</div>
相关问题