移动端vue项目的类微信聊天功能知识积累

一:让div可以实现长按出现浏览器的复制、粘贴、全选、搜索功能提示框

        div设置css样式如下(让div可以选择):

user-select: auto;
cursor: text;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 中模拟微信聊天内容置底可以使用以下方法: 1. 使用 `ref` 绑定聊天内容区域的元素,并在 `mounted` 钩子函数中获取该元素的高度。 ```vue <template> <div class="chat-wrapper" ref="chatWrapper"> <!-- 聊天内容区域 --> </div> </template> <script> export default { mounted() { this.chatWrapperHeight = this.$refs.chatWrapper.clientHeight; } } </script> <style> .chat-wrapper { height: 300px; /* 聊天内容区域的高度 */ overflow-y: scroll; } </style> ``` 2. 监听聊天内容区域的高度变化,如果高度变大了,说明有新消息到来,将聊天内容区域的滚动条置于底部。 ```vue <template> <div class="chat-wrapper" ref="chatWrapper" @DOMNodeInserted="scrollToBottom"> <!-- 聊天内容区域 --> </div> </template> <script> export default { mounted() { this.chatWrapperHeight = this.$refs.chatWrapper.clientHeight; }, methods: { scrollToBottom() { const chatWrapper = this.$refs.chatWrapper; const isScrolledToBottom = chatWrapper.scrollHeight - chatWrapper.clientHeight <= chatWrapper.scrollTop + 1; if (isScrolledToBottom) { chatWrapper.scrollTop = chatWrapper.scrollHeight - chatWrapper.clientHeight; } } } } </script> <style> .chat-wrapper { height: 300px; /* 聊天内容区域的高度 */ overflow-y: scroll; } </style> ``` 这段代码使用了 `DOMNodeInserted` 事件来监听聊天内容区域的高度变化,一旦聊天内容区域的高度变大了,就将滚动条滚动到底部,使用户可以看到最新的消息。其中,`isScrolledToBottom` 变量用于判断滚动条是否已经滚动到底部,如果已经滚动到底部,则不需要再次滚动,避免出现滚动条抖动的情况。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值