Vue 3 Masonry Layout Component

1.1.3 · active · verified Sun Apr 19

vue-next-masonry is a UI component library offering a responsive masonry layout for Vue 3 applications. It functions as a direct port of the well-established `vue-masonry-css` library, specifically adapted for the Vue 3 composition API and ecosystem. The current stable version is 1.1.3, indicating ongoing maintenance and compatibility with recent Vue 3 releases. Its release cadence appears to be driven by bug fixes, minor enhancements, and alignment with Vue 3's evolution rather than a strict schedule. A key differentiator is its seamless integration into Vue 3 projects for developers familiar with the Vue 2 `vue-masonry-css` component, providing a familiar API while leveraging Vue 3's performance improvements. It aims to provide an easy-to-use `<masonry>` component that automatically arranges child elements into a grid with variable column heights, optimizing space and improving visual presentation for galleries, portfolios, and lists.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates global registration of the masonry component and its basic usage in a Vue 3 template with dynamic item heights.

import { createApp } from 'vue';
import masonry from 'vue-next-masonry';

// Assume your root component is App.vue
import App from './App.vue';

const app = createApp(App);

app.use(masonry);

app.mount('#app');

// In your App.vue or any other component's template:
// <template>
//   <masonry :cols="{ default: 3, 700: 2, 500: 1 }" :gutter="20">
//     <div v-for="(item, index) in 10" :key="index" class="masonry-item" :style="{ height: `${50 + Math.random() * 150}px` }">
//       Item {{ item }}
//     </div>
//   </masonry>
// </template>
//
// <style>
// .masonry-item {
//   background-color: #f0f0f0;
//   border: 1px solid #ccc;
//   padding: 10px;
//   margin-bottom: 20px; /* Gutter is handled by the component, this is just for visual clarity */
//   display: flex;
//   align-items: center;
//   justify-content: center;
// }
// </style>

view raw JSON →