vue3 瀑布流插件 vue-masonry 使用

官方文档:https://github.com/shershen08/vue-masonry

VueMasonry (v3 + ts + vite)

  1. 安装

    pnpm install vue-masonry --save
    
  2. 引入

    // main.ts
    import { VueMasonryPlugin } from 'vue-masonry';
    app.use(VueMasonryPlugin);
    

    在这里插入图片描述

  3. 使用
    在父元素上添加 v-masonry transition-duration="0.25s" item-selector=".item"(.item 必须和子元素的类名一致)
    在这里插入图片描述
    更多配置请查看官网:properties

  4. 手动刷新 $redrawVueMasonry
    方法一:

    // 获取当前实例,调用 $redrawVueMasonry
    const that = getCurrentInstance()?.appContext.config.globalProperties;
    // 调用
    that?.$redrawVueMasonry();
    

    方法二:

    // 使用 provide / inject
    const $redrawVueMasonry = inject('redrawVueMasonry') as Function;
    // 调用
    $redrawVueMasonry();
    

    方法三

    // 往要渲染的数据里添加新的数据,
    // v-for 循环时 再用v-if过滤一下
    
    // 示例
    imageList.push({ id: 'temp' + Math.random(), ... })
    // html:
    <template>
    <div v-for="item in imageList" :key="item.id">
    	<div v-if="!id.include('temp')">...</div>
    </div>
    </template>
    

    源码:
    在这里插入图片描述

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值