Vue Grid Layout v3

3.1.2 · active · verified Sun Apr 19

vue-grid-layout-v3 is a comprehensive and responsive grid layout system for Vue.js, enabling draggable and resizable widgets within a grid structure. It is heavily inspired by React-Grid-Layout and provides features such as static widgets, bounds checking during dragging and resizing, the ability to add or remove widgets dynamically, layout serialization, and automatic RTL support. The package specifically targets Vue 3.2+ environments, with the current stable version being 3.1.2. It maintains an active release cadence, providing minor updates and bug fixes for the 3.x branch. Key differentiators include its robust feature set for creating interactive dashboards and configurable layouts, making it a powerful tool for applications requiring dynamic user interfaces, and its clear lineage from a popular React library. This version represents a modern adaptation for the Vue 3 ecosystem, distinct from earlier versions supporting Vue 1 and Vue 2.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic draggable and resizable grid layout using `vue-grid-layout-v3` in a Vue 3 application. It initializes a responsive grid with several items, allowing users to interactively rearrange and resize them, and logs layout changes.

import { createApp, ref } from 'vue';
import { GridLayout, GridItem } from 'vue-grid-layout-v3';

const app = createApp({
  components: {
    GridLayout,
    GridItem,
  },
  setup() {
    const layout = ref([
      { x: 0, y: 0, w: 2, h: 2, i: '0', static: false },
      { x: 2, y: 0, w: 2, h: 4, i: '1', resizable: true },
      { x: 4, y: 0, w: 2, h: 5, i: '2', draggable: true },
      { x: 6, y: 0, w: 2, h: 3, i: '3', minW: 2, maxW: 4 },
      { x: 8, y: 0, w: 2, h: 3, i: '4' },
      { x: 10, y: 0, w: 2, h: 3, i: '5' }
    ]);

    const onLayoutUpdated = (newLayout) => {
      console.log('Layout updated:', newLayout);
    };

    return {
      layout,
      onLayoutUpdated,
    };
  },
  template: `
    <div style="width: 100%; height: 500px; border: 1px solid #ccc; padding: 10px;">
      <GridLayout
        v-model:layout="layout"
        :col-num="12"
        :row-height="30"
        :is-draggable="true"
        :is-resizable="true"
        :vertical-compact="true"
        :use-css-transforms="true"
        @layout-updated="onLayoutUpdated"
        style="min-height: 400px;"
      >
        <GridItem
          v-for="item in layout"
          :x="item.x"
          :y="item.y"
          :w="item.w"
          :h="item.h"
          :i="item.i"
          :key="item.i"
          :is-draggable="item.draggable !== undefined ? item.draggable : true"
          :is-resizable="item.resizable !== undefined ? item.resizable : true"
          :static="item.static"
          style="background-color: #f0f0f0; border: 1px solid #ddd; display: flex; align-items: center; justify-content: center;"
        >
          {{ item.i }}
        </GridItem>
      </GridLayout>
    </div>
  `
});

app.mount('#app');

view raw JSON →