最流畅vue瀑布流组件vue-waterfall-rapid

vue-waterfall-rapid

💯最流畅的vue瀑布流组件,支持各种使用场景,灵活度高,简单易用。

1.支持没有图片高度 && 不影响渲染速度。
2.支持自由绑定动画。
3.支持根据容器改变自适应。
4.支持无图。

github https://github.com/1977474741/vue-waterfall-rapid
Demo https://coding-pages-bucket-415964-8382475-13401-506140-1252701316.cos-website.ap-hongkong.myqcloud.com

使用

1.安装
npm i vue-waterfall-rapid
2.示例

template

<div class="main" @scroll="scroll">
    <waterfall :col="col" :autoResize="autoResize" :moveTransitionDuration="0.4" :fillBox="fillBox" :col-width="colWidth" :list="list" ref="waterfall" imgKey="src">
        <!-- 两种图片绑定模式
        1.指定图片的Key( imgKey="src")
        2.在img标签上加class( class="waterfall-img") -->
        <!-- img标签如果设置宽高会渲染的更快 -->
        <div class="waterfall-item" :class="{bounceIn:item.state == 'show'}" slot-scope="item">
            <img v-if="item.data.src" style="width: 100%" class="waterfall-img" :src="item.data.src">
            {{item.index}}-{{item.data.text}}
        </div>
    </waterfall>
</div>

javascript

import waterfall from 'vue-waterfall-rapid'
export default {
    name: 'vue-waterfall-rapid',
    components: {
        waterfall
    },
    data(){
        return{
            //是否根据容器尺寸自动计算重绘
            autoResize:true,
            //是否始终填满容器
            fillBox: false,
            //列宽-有指定列数则此属性失效
            colWidth: window.innerWidth / 5,
            //列数
            col: 0,
            //图片数据
            list: []
        }
    },
    mounted(){
        this.$refs.waterfall.onRender = (res)=>{
            console.log('渲染完毕',res);
        }
    },
    methods:{
        scroll(e){
            // console.log(e)
        }
    }
}

插槽内属性(slot-scope)

{
    index: 0, //当前元素下标
    data: {}, //当前元素数据
    state: 'show', //当前元素的渲染状态
}
/**
* state对应值说明:
* 'complete', // 元素内图片加载完成
* 'show', // 元素显示(可以用来绑定显示动画)
*/

参数

属性类型缺省值描述
listArray[]要渲染的数据
imgKeyStringsrc指定图片在list里的key(或者在img标签上加 class=“waterfall-img”)
colNumber3列数,手动设置时会覆盖掉colWidth
colWidthNumber0(px)列宽,和col冲突时,col优先
autoResizeBooleanfalse是否随容器宽度变化重绘
fillBoxBooleanfalse是否填充满容器
moveModeStringtransform定位方式(transform、convention)
moveTransitionDurationNumber0.4(s)位置变化时的过渡时间

函数

函数名参数返回值描述
repaintsstart(开始的下标),duration(过渡时间 s)手动重绘

事件

属性名回调内返回值描述
onRendercallback{ cause(导致渲染的原因),start(开始渲染的下标) }渲染完毕事件
/**
 * cause对应值说明:
 * 'data', // 数据改变
 * 'resize', // 容器宽度改变
 */

有更好的建议欢迎提issues或者提pr

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`vue-beautiful-chat`是一个基于Vue2的聊天组件,支持实时聊天、多人聊天、消息记录等功能,使用起来非常方便。下面是使用`vue-beautiful-chat`的步骤: 1. 安装`vue-beautiful-chat` 可以使用npm命令进行安装:`npm install vue-beautiful-chat` 2. 引入并使用组件Vue组件中引入`vue-beautiful-chat`组件,并在`template`中使用: ```html <template> <div> <h1>聊天室</h1> <vue-beautiful-chat :messages="messages" @message="handleMessage" /> </div> </template> <script> import VueBeautifulChat from "vue-beautiful-chat"; export default { components: { VueBeautifulChat, }, data() { return { messages: [], }; }, methods: { handleMessage(message) { // 处理接收到的消息 console.log("Received message:", message); }, }, }; </script> ``` 在上面的代码中,`vue-beautiful-chat`组件的属性`messages`用来绑定消息数组,`@message`事件用来处理接收到的消息。 3. 发送消息 可以使用`vue-beautiful-chat`组件提供的`sendMessage`方法发送消息: ```javascript this.$refs.chat.sendMessage({ type: "text", content: "Hello, world!", sender: { name: "John Doe", avatar: "https://randomuser.me/api/portraits/men/1.jpg", }, }); ``` 其中,`type`表示消息类型(可以是文本、图片、音频等),`content`表示消息内容,`sender`表示消息发送者的信息。 4. 消息记录 `vue-beautiful-chat`组件提供了`loadMessages`方法用来加载历史消息记录: ```javascript this.$refs.chat.loadMessages([ { type: "text", content: "Hello, world!", sender: { name: "John Doe", avatar: "https://randomuser.me/api/portraits/men/1.jpg", }, }, // ... ]); ``` 以上是使用`vue-beautiful-chat`的基本步骤,具体的功能和使用方法可以参考`vue-beautiful-chat`的官方文档。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值