ElementPlus Space 間距

2021-09-07 14:28 更新

Space 間距

雖然我們擁有 Divider 組件, 但很多時候我們需要不是一個被 Divider 組件 分割開的頁面結(jié)構(gòu), 因此我們會重復(fù)的使用很多的 Divider 組件, 這在我們的開發(fā)效率上造成了一定的困擾, 間距組件就是為了解決這種困擾應(yīng)運而生的.

基礎(chǔ)用法


用 fill 讓子節(jié)點自動填充容器

<template>
  <div>
    <div style="margin-bottom:15px">
      fill: <el-switch v-model="fill"></el-switch>
    </div>
    <el-space :fill="fill" wrap>
      <el-card class="box-card" v-for="i in 3" :key="i">
        <template #header>
          <div class="card-header">
            <span>Card name</span>
            <el-button class="button" type="text">Operation button</el-button>
          </div>
        </template>
        <div v-for="o in 4" :key="o" class="text item">
          {{ 'List item ' + o }}
        </div>
      </el-card>
    </el-space>
  </div>
</template>

<script>
  export default {
    data() {
      return { fill: true }
    },
  }
</script>

也可以使用 fillRatio 參數(shù),自定義填充的比例,默認(rèn)值為 100,代表基于父容器寬度的 100% 進行填充

需要注意的是,水平布局和垂直布局的表現(xiàn)形式稍有不同,具體的效果可以查看下面的例子


用 ?fillRatio ?自定義填充比例

<template>
  <div>
    <div style="margin-bottom: 15px">
      direction:
      <el-radio v-model="direction" label="horizontal">horizontal</el-radio>
      <el-radio v-model="direction" label="vertical">vertical</el-radio>
    </div>
    <div style="margin-bottom: 15px">
      fillRatio:<el-slider v-model="fillRatio"></el-slider>
    </div>
    <el-space
      fill
      wrap
      :fillRatio="fillRatio"
      :direction="direction"
      style=" width: 100%"
    >
      <el-card class="box-card" v-for="i in 5" :key="i">
        <template #header>
          <div class="card-header">
            <span>Card name</span>
            <el-button class="button" type="text">Operation button</el-button>
          </div>
        </template>
        <div v-for="o in 4" :key="o" class="text item">
          {{ 'List item ' + o }}
        </div>
      </el-card>
    </el-space>
  </div>
</template>

<script>
  export default {
    data() {
      return { direction: 'horizontal', fillRatio: 30 }
    },
  }
</script>

Space Attributes

參數(shù)說明類型可選值默認(rèn)值
alignment對齊的方式stringalign-items'center'
class類名string / Array<Object | String> / Object--
direction排列的方向stringvertical/horizontalhorizontal
prefixCls給 space-items 的類名前綴stringel-space-
style額外樣式string / Array<Object | String> / Object--
spacer間隔符string / number / VNode--
size間隔大小string / number / [number, number]-'small'
wrap設(shè)置是否自動折行booleantrue / falsefalse
fill子元素是否填充父容器booleantrue / falsefalse
fillRatio填充父容器的比例number-100


Space Slot

name說明
default需要添加間隔的元素


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號