npm install vue-masonry --save
import {VueMasonryPlugin} from 'vue-masonry';
Vue.use(VueMasonryPlugin)
<template>
<div>
<div v-masonry transition-duration="0.3s" i tem-selector=".item">
<div v-masonry-tile class="item" v-for="item in blocks" :key="item.id">
<img :src="item.url" alt="">
div>
div>
div>
template>
<script>
export default {
data () {
return {
blocks: [
{
id: 1,
url: 'https://cdn.pixabay.com/photo/2022/07/11/19/51/sea-7315960__340.jpg'
},
{
id: 2,
url: 'https://cdn.pixabay.com/photo/2022/07/07/07/24/clouds-7306684__340.jpg'
},
{
id: 3,
url: 'https://cdn.pixabay.com/photo/2019/07/23/13/51/shepherd-dog-4357790__340.jpg'
},
{
id: 4,
url: 'https://cdn.pixabay.com/photo/2022/07/11/19/51/sea-7315960__340.jpg'
},
{
id: 5,
url: 'https://cdn.pixabay.com/photo/2022/07/11/19/51/sea-7315960__340.jpg'
},
{
id: 6,
url: 'https://cdn.pixabay.com/photo/2019/07/23/13/51/shepherd-dog-4357790__340.jpg'
},
]
}
}
}
script>
感觉文章好的话记得点个心心和关注和收藏,有错的地方麻烦指正一下,如果需要转载,请标明出处,多谢!!!