分享一个vue头像组件 vue-avatar

这两天做前端项目,用到头像,之前用的是组件是自己写的,但是不够酷炫,网上找了个头像组件vue-avatar, 感觉还是非常好用的。

安装

npm install vue-avatar

vue中引入和使用

import Avatar from 'vue-avatar'
 
export default {
  ...
  components: {
    Avatar
  },
  ...
}
<avatar username="胡鹏" background-color="#fff" color="rgb(255, 208, 75)"></avatar>

看下头像的效果,感觉咋样?

参考文档https://www.npmjs.com/package/vue-avatar

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
`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`的官方文档。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值