vue瀑布流布局插件vue-masonry

4 篇文章 0 订阅
  1. 插件npm网址 https://www.npmjs.com/package/vue-masonry
  2. github :https://github.com/shershen08/vue-masonry
  3. 安装 npm install vue-masonry --save || yarn add vue-masonry --save
  4. //main.js
    import {VueMasonryPlugin} from 'vue-masonry'
    Vue.use(VueMasonryPlugin)
    
  5. <div v-masonry transiton-duration="0.3s" item-selector=".card" gutter="10">
        <div v-masonry-tile class="card" v-for="(item,index) in testData" :key="index" >
    	/*内容*/
    	</div>
    </div>
    
  6. 一些属性
    this.$redrawVueMasonry(); 重加载
    item-selector=".item" 列表DOM项目选择器(类)
    transition-duration="0.3s 过渡效果
    gutter=".gutter-block-selector 项目元素之间的水平间距

vue3

1.重加载

import { defineComponent, ref, nextTick, getCurrentInstance } from 'vue';
const instance = getCurrentInstance();
const _this = instance.appContext.config.globalProperties;
 _this.$redrawVueMasonry();
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然,我可以为您提供一个使用Vue实现的瀑布流布局案例。 首先,您需要安装Vuevue-masonry-css插件。您可以通过以下命令来安装它们: ``` npm install vue vue-masonry-css``` 接下来,您可以创建一个Vue组件来实现瀑布流布局。下面是一个简单的示例: ```vue<template> <div class="masonry"> <div v-for="(item, index) in items" :key="index" class="item"> <!-- 在这里放置您的内容 --> <img :src="item.imageUrl" alt="Item Image" /> <p>{{ item.title }}</p> </div> </div> </template> <script> import VueMasonryCss from "vue-masonry-css"; export default { name: "MasonryLayout", data() { return { items: [ { imageUrl: "https://example.com/image1.jpg", title: "Item1" }, { imageUrl: "https://example.com/image2.jpg", title: "Item2" }, // 添加更多项目... ] }; }, components: { VueMasonryCss } }; </script> <style scoped> .masonry { display: flex; flex-wrap: wrap; } .item { width:200px; /* 每个项的宽度 */ } </style> ``` 在上述示例中,我们使用了vue-masonry-css插件来实现瀑布流布局。通过在外部容器上添加`.masonry`类,并设置`display: flex; flex-wrap: wrap;`,我们创建了一个弹性布局并使其换行。 每个项使用`.item`类来设置宽度,您可以根据自己的需求进行调整。 在`data`中,我们定义了一个`items`数组来存储每个项目的数据。您可以根据自己的需求修改该数组,并在模板中使用`v-for`指令来循环渲染每个项目。 这只是一个简单的示例,您可以根据自己的需求进行更改和扩展。希望对您有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值