Skip to content

栅格 Grid

流体风格的布局容器。

basic

设定子组件之间的间距。

预览代码
<script setup lang="ts">
  defineOptions({ name: 'ex-grid-basic' })
</script>

<template>
  <g-grid container justify-content="center" :spacing="3">
    <g-grid :xs="6">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="6">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="6">
      <g-card shadow />
    </g-grid>
  </g-grid>
</template>

<style lang="scss" scoped>
.card {
  width: 100%;
  height: 100px;
}
</style>

fluid

自动换行。

预览代码
<script setup lang="ts">
  defineOptions({ name: 'ex-grid-fluid' })
</script>

<template>
  <g-grid container justify-content="center" :spacing="3">
    <g-grid :xs="24">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="12">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="12">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="6">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="6">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="6">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="6">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="6">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="12">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="6">
      <g-card shadow />
    </g-grid>
  </g-grid>
</template>

responsive

在不同的屏幕宽度下展示不同的布局。

预览代码
<script setup lang="ts">
  defineOptions({ name: 'ex-grid-responsive' })
</script>

<template>
  <g-grid container justify-content="center" :spacing="3">
    <g-grid :xs="24" :md="12">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="24" :md="12">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="24" :md="6">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="24" :md="6">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="24" :md="6">
      <g-card shadow />
    </g-grid>
  </g-grid>
</template>

hidden

当单位大小为 0 时会自动隐藏当前元素。

预览代码
<script setup lang="ts">
  defineOptions({ name: 'ex-grid-hidden' })
</script>

<template>
  <g-grid container justify-content="center" :spacing="3">
    <g-grid :xs="12" :sm="0">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="12" :sm="0">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="24">
      <g-card shadow />
    </g-grid>

    <g-grid :xs="24">
      <g-card shadow />
    </g-grid>
  </g-grid>
</template>

auto width

自动分配剩余宽度。

预览代码
<script setup lang="ts">
  defineOptions({ name: 'ex-grid-auto-width' })
</script>

<template>
  <g-grid container justify-content="center" :spacing="3">
    <g-grid xs>
      <g-card shadow />
    </g-grid>

    <g-grid xs>
      <g-card shadow />
    </g-grid>

    <g-grid xs>
      <g-card shadow />
    </g-grid>
  </g-grid>

  <g-grid container justify-content="center" :spacing="3">
    <g-grid xs>
      <g-card shadow />
    </g-grid>

    <g-grid :xs="12">
      <g-card shadow />
    </g-grid>

    <g-grid xs>
      <g-card shadow />
    </g-grid>
  </g-grid>
</template>

Attributes

属性描述类型推荐值默认
container容器属性boolean-false
spacing子组件间距number-0
justifyContentcss 属性"justify-content"stringjustify-contentflex-start
alignItemscss 属性"align-items"stringalign-itemsstretch
alignContentcss 属性"align-content"stringalign-contentstretch
directioncss 属性"flex-direction"stringflex-directionrow
wrapcss 属性"flex-wrap"stringflex-wrapwrap
xs栅格宽度,影响 xs 断点与更宽的屏幕number / boolean0-24,true,falsefalse
sm栅格宽度,影响 sm 断点与更宽的屏幕number / boolean0-24,true,falsefalse
md栅格宽度,影响 md 断点与更宽的屏幕number / boolean0-24,true,falsefalse
lg栅格宽度,影响 lg 断点与更宽的屏幕number / boolean0-24,true,falsefalse
xl栅格宽度,影响 xl 断点与更宽的屏幕number / boolean0-24,true,falsefalse

Released under the MIT License.