Vue CSS Masonry Component

1.0.3 · maintenance · verified Sun Apr 19

Vue-masonry-css is a Vue.js component that provides a masonry layout powered by CSS, prioritizing fast rendering and optimal utilization of Vue's Virtual DOM. It is dependency-free, specifically avoiding external libraries like jQuery or traditional JavaScript-based masonry solutions (e.g., DeSandro Masonry) which often introduce performance overhead through double-rendering. The current stable version is 1.0.3, and it appears to follow a slow, stable release cadence given its nature as a lightweight, dependency-free UI component. Key differentiators include its responsive-by-default behavior, compatibility with IE10+ (including IE9, though this might be an outdated claim), and seamless integration with existing CSS animations. It achieves its layout using plain divs and a touch of flexbox, offering a simple interface to define columns and gutter sizes based on responsive breakpoints. Notable limitations include its inability to handle elements with varying widths within a single column and its intentional omission of height-based sorting to maintain high rendering performance.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and globally register the `vue-masonry-css` plugin, then use the `<masonry>` component in a Vue 2 template with responsive column and gutter configurations.

import Vue from 'vue';
import VueMasonry from 'vue-masonry-css';

Vue.use(VueMasonry);

new Vue({
  el: '#app',
  data: {
    items: Array.from({ length: 15 }, (_, i) => ({ id: i + 1, height: `${Math.floor(Math.random() * 100) + 100}px` }))
  },
  template: `
    <div id="app">
      <h1>My Masonry Layout</h1>
      <masonry
        :cols="{default: 4, 1000: 3, 700: 2, 400: 1}"
        :gutter="{default: '30px', 700: '15px'}"
      >
        <div 
          v-for="(item, index) in items" 
          :key="item.id" 
          :style="{ height: item.height, background: '#f0f0f0', padding: '15px', border: '1px solid #ddd', marginBottom: '30px' }"
        >
          Item: {{ index + 1 }}
        </div>
      </masonry>
    </div>
  `
});

view raw JSON →