Skip to content

Grid - Vant 4

Grid

Create stunning grid layouts with ease! ✨ Perfect for organizing content, navigation menus, and interactive dashboards with responsive design.

📋 Intro

Divide your page into perfectly aligned blocks! 🎯 Grid provides flexible layout solutions for displaying content or creating intuitive navigation systems with equal-width columns.

📦 Install

Get started in seconds! 🚀 Register Grid components globally for seamless integration across your application.

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

js
import { createApp } from'vue'; import { Grid, GridItem } from'vant'; const app = createApp(); app.use(Grid); app.use(GridItem);

🎨 Usage

Transform your layouts with powerful grid configurations! 💫 From basic grids to advanced customizations, create beautiful and functional interfaces.

🌟 Basic Usage

html

🔢 Column Num

Control your layout density! 📊 Adjust the number of columns to fit your content perfectly and create responsive designs.

html

🎨 Custom Content

Unleash your creativity! ✨ Add custom icons, text, and interactive elements to create unique grid experiences.

html

⬜ Square

Perfect proportions every time! 📐 Create square grid items for consistent, balanced layouts that look great on any device.

html

📏 Gutter

Add breathing room to your layout! 🌬️ Control spacing between grid items for better visual hierarchy and readability.

html

↔️ Horizontal

Flexible content arrangement! 🔄 Switch between vertical and horizontal layouts to match your design requirements.

html

🛣️ Route

Seamless navigation integration! 🧭 Connect grid items to routes for intuitive app navigation and user flow.

html

🔴 Show Badge

Add visual indicators and notifications! 🔔 Display badges, dots, and counters to highlight important information and updates.

html

🔧 API

Complete control over your grid layout! 🎛️ Configure every aspect from columns to styling with these comprehensive options.

📋 Grid Props

AttributeDescriptionTypeDefault
column-numColumn Num*numberstring*
icon-sizeIcon size*numberstring*
gutterGutter*numberstring*
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
reverseWhether to reverse the position of icon and textbooleanfalse

🎯 GridItem Props

Customize each grid item with precision! ✨ Control appearance, behavior, and navigation for perfect user experiences.

AttributeDescriptionTypeDefault
textTextstring-
iconIcon name or URLstring-
icon-prefixIcon className prefixstringvan-icon
icon-colorIcon colorstring-
dotWhether to show red dotbooleanfalse
badgeContent of the badge*numberstring*
badge-propsProps of Badge, see Badge - propsBadgeProps-

| url | Link URL | string | - | | to | The target route should navigate to when clicked on, same as the to prop of Vue Router | string | object | - |

| replace | If true, the navigation will not leave a history record | boolean | false |

🎯 GridItem Events

Stay connected with user interactions! 📡 Handle clicks and touches to create responsive and engaging grid experiences.

EventDescriptionArguments
clickEmitted when component is clickedevent: MouseEvent

🎨 GridItem Slots

Unlimited customization possibilities! ✨ Replace default content with your own components and designs.

NameDescription
defaultCustom content
iconCustom icon
textCustom text

📝 Types

Full TypeScript support for enhanced development! 🚀 Import these types for better code completion and type safety.

The component exports the following type definitions:

ts
importtype { GridProps, GridDirection, GridItemProps } from'vant';

🎨 Theming

Make it uniquely yours! 🌈 Customize every visual aspect with CSS variables for perfect brand alignment.

🎛️ 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-backgroundvar(--van-background-2)-
--van-grid-item-content-active-colorvar(--van-active-color)-
--van-grid-item-icon-size28px-
--van-grid-item-text-colorvar(--van-text-color)-
--van-grid-item-text-font-sizevar(--van-font-size-sm)-

Explore related components and features! 🔗 Build comprehensive layouts and navigation systems with these complementary tools.

  • Icon - Beautiful icons for grid items
  • Badge - Notification badges and indicators
  • Button - Interactive buttons and actions
  • Cell - List-style content cells
  • Card - Content cards and containers
  • Space - Layout spacing utilities
  • Col - Column layout system
  • Tabbar - Bottom navigation tabs
  • NavBar - Top navigation bar
  • Sidebar - Side navigation menu
  • ConfigProvider - Global configuration
  • Advanced Usage - Advanced implementation patterns

Enterprise-level mobile solution based on Vant