import{o as t,a,y as n}from"./vue-libs.b44bc779.js";const l={class:"van-doc-markdown-body"},e=n(`

Grid

Intro

Used to divide the page into blocks of equal width in the horizontal direction for displaying content or page navigation.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { Grid, GridItem } from 'vant';

const app = createApp();
app.use(Grid);
app.use(GridItem);

Usage

Basic Usage

<van-grid>
  <van-grid-item icon="photo-o" text="Text" />
  <van-grid-item icon="photo-o" text="Text" />
  <van-grid-item icon="photo-o" text="Text" />
  <van-grid-item icon="photo-o" text="Text" />
</van-grid>

Column Num

<van-grid :column-num="3">
  <van-grid-item v-for="value in 6" :key="value" icon="photo-o" text="Text" />
</van-grid>

Custom Content

<van-grid :border="false" :column-num="3">
  <van-grid-item>
    <van-image
      src="https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg"
    />
  </van-grid-item>
  <van-grid-item>
    <van-image
      src="https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg"
    />
  </van-grid-item>
  <van-grid-item>
    <van-image
      src="https://fastly.jsdelivr.net/npm/@vant/assets/apple-3.jpeg"
    />
  </van-grid-item>
</van-grid>

Square

<van-grid square>
  <van-grid-item v-for="value in 8" :key="value" icon="photo-o" text="Text" />
</van-grid>

Gutter

<van-grid :gutter="10">
  <van-grid-item v-for="value in 8" :key="value" icon="photo-o" text="Text" />
</van-grid>

Horizontal

<van-grid direction="horizontal" :column-num="3">
  <van-grid-item icon="photo-o" text="\u6587\u5B57" />
  <van-grid-item icon="photo-o" text="\u6587\u5B57" />
  <van-grid-item icon="photo-o" text="\u6587\u5B57" />
</van-grid>

Route

<van-grid clickable :column-num="2">
  <van-grid-item icon="home-o" text="Vue Router" to="/" />
  <van-grid-item icon="search" text="URL" url="https://github.com" />
</van-grid>

Show Badge

<van-grid :column-num="2">
  <van-grid-item icon="home-o" text="Text" dot />
  <van-grid-item icon="search" text="Text" badge="99+" />
</van-grid>

API

Grid Props

AttributeDescriptionTypeDefault
column-numColumn Numnumber | string4
icon-sizeIcon sizenumber | string28px
gutterGutternumber | string0
borderWhether to show borderbooleantrue
centerWhether to center contentbooleantrue
squareWhether to be square shapebooleanfalse
clickableWhether to show click feedback when clickedbooleanfalse
directionContent arrangement direction, can be set to horizontalstringvertical
reverse v3.1.0Whether to reverse the position of icon and textbooleanfalse

GridItem Props

AttributeDescriptionTypeDefault
textTextstring-
iconIcon name or URLstring-
icon-prefixIcon className prefixstringvan-icon
icon-colorIcon colorstring-
dotWhether to show red dotbooleanfalse
badgeContent of the badgenumber | string-
badge-props v3.2.8Props of Badge, see Badge - propsBadgeProps-
urlLink URLstring-
toTarget route of the link, same as to of vue-routerstring | object-
replaceIf true, the navigation will not leave a history recordbooleanfalse

GridItem Events

EventDescriptionArguments
clickEmitted when component is clickedevent: MouseEvent

GridItem Slots

NameDescription
defaultCustom content
iconCustom icon
textCustom text

Types

The component exports the following type definitions:

import type { GridProps, GridDirection, GridItemProps } from 'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-grid-item-content-paddingvar(--van-padding-md) var(--van-padding-xs)-
--van-grid-item-content-background-colorvar(--van-background-color-light)-
--van-grid-item-content-active-colorvar(--van-active-color)-
--van-grid-item-icon-size28px-
--van-grid-item-text-colorvar(--van-gray-7)-
--van-grid-item-text-font-sizevar(--van-font-size-sm)-
`,20),p=[e],h={__name:"README",setup(d,{expose:s}){return s({frontmatter:{}}),(r,c)=>(t(),a("div",l,p))}};export{h as default};