Skip to content

Col Layout Rules

TIP

All components support layout configuration. See

naive-ui Grid Layout Col props

Custom Form Layout

Configuration Method

Configure component layout using rule.col. Naive UI uses a 24-column grid system with default span: 24 (full row).

js
const rule = {
    type: 'input',
    field: 'username',
    title: 'Username',
    col: {
        span: 12,  // 12 columns (half width)
    }
}

Configuration Parameters

NameTypeDefault ValueDescription
spannumber24Number of grid columns occupied
offsetnumber0Number of spacing columns on the left
pushnumber0Number of columns to move right
pullnumber0Number of columns to move left

Layout Examples

Basic Layout

Single Column Layout (Default)

js
const rule = {
    type: 'input',
    title: 'Product Name',
    field: 'goods_name',
    // Default: span: 24 (full row)
}

Two Column Layout

js
const rule = [
    {
        type: 'input',
        title: 'Product Name',
        field: 'goods_name',
        col: {
            span: 12,  // 12 columns (half width)
        }
    },
    {
        type: 'input',
        title: 'Product Price',
        field: 'price',
        col: {
            span: 12,  // 12 columns (half width)
        }
    }
]

Three Column Layout

js
const rule = [
    {
        type: 'input',
        title: 'Product Name',
        field: 'goods_name',
        col: {
            span: 8,  // 8 columns (1/3 width)
        }
    },
    {
        type: 'input',
        title: 'Product Price',
        field: 'price',
        col: {
            span: 8,  // 8 columns (1/3 width)
        }
    },
    {
        type: 'input',
        title: 'Product Stock',
        field: 'stock',
        col: {
            span: 8,  // 8 columns (1/3 width)
        }
    }
]

Offset Layout

Using offset to Set Left Offset

js
const rule = {
    type: 'input',
    title: 'Product Name',
    field: 'goods_name',
    col: {
        span: 12,
        offset: 6,  // Offset 6 columns left
    }
}

Using push to Move Right

js
const rule = {
    type: 'input',
    title: 'Product Name',
    field: 'goods_name',
    col: {
        span: 8,
        push: 8,  // Push 8 columns right
    }
}

Using pull to Move Left

js
const rule = {
    type: 'input',
    title: 'Product Name',
    field: 'goods_name',
    col: {
        span: 8,
        pull: 4,  // Pull 4 columns left
    }
}

Using Row and Col Components for Layout

Use row and col components to manually control layout instead of rule.col.

Basic Usage

js
const rule = [
    {
        type: 'row',
        native: true,
        children: [
            {
                type: 'col',
                props: {
                    span: 12,
                },
                native: true,
                children: [
                    {
                        type: 'input',
                        title: 'Product Name',
                        field: 'goods_name',
                    }
                ]
            },
            {
                type: 'col',
                props: {
                    span: 12,
                },
                native: true,
                children: [
                    {
                        type: 'input',
                        title: 'Product Price',
                        field: 'price',
                    }
                ]
            }
        ]
    }
]

Multi-Row Layout

js
const rule = [
    {
        type: 'row',
        native: true,
        children: [
            {
                type: 'col',
                props: { span: 12 },
                native: true,
                children: [
                    {
                        type: 'input',
                        title: 'Product Name',
                        field: 'goods_name',
                    }
                ]
            },
            {
                type: 'col',
                props: { span: 12 },
                native: true,
                children: [
                    {
                        type: 'select',
                        title: 'Product Category',
                        field: 'category',
                    }
                ]
            }
        ]
    },
    {
        type: 'row',
        native: true,
        children: [
            {
                type: 'col',
                props: { span: 8 },
                native: true,
                children: [
                    {
                        type: 'input-number',
                        title: 'Product Price',
                        field: 'price',
                    }
                ]
            },
            {
                type: 'col',
                props: { span: 8 },
                native: true,
                children: [
                    {
                        type: 'input-number',
                        title: 'Product Stock',
                        field: 'stock',
                    }
                ]
            },
            {
                type: 'col',
                props: { span: 8 },
                native: true,
                children: [
                    {
                        type: 'switch',
                        title: 'On Sale',
                        field: 'is_show',
                    }
                ]
            }
        ]
    }
]

Tips

  • When using row and col components, set native: true to generate components as-is
  • Naive UI uses a 24-grid system
  • You can set related properties through row's props

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.