The specific code for sending emoticons in the vue chat box and sending emoticons in the vue interface is for your reference. The specific content is as follows 1. When sending a message, determine whether the message is an emoticon, the emoticon type: 3, content: [love], and store it in the database <img v-else-if="chatItem.type === 3" :src="emojiUrl + emojiMap[chatItem.content]" style="width:25px;height:25px" /> 1.textElement.vue <template> <div class="text-element-wrapper" > <div class="text-element"> <div :class="isMine ? 'element-send' : 'element-received'"> <p>{{ date }}</p> <!-- Text --> <span>{{ chatItem.content }}</span> <span v-if="chatItem.type === 1">{{ chatItem.content }}</span> <!-- Expression --> <img v-else-if="chatItem.type === 3" :src="emojiUrl + emojiMap[chatItem.content]" style="width:25px;height:25px" /> </div> <div :class="isMine ? 'send-img' : 'received-img'"> <img :src="chatItem.from_headimg" width="40px" height="40px"/> </div> </div> </div> </template> <script> // import decodeText from '../../../untils/decodeText' import { getFullDate } from '../../../untils/common' import {emojiMap, emojiUrl} from '../../../untils/emojiMap' export default { name: 'TextElement', props: ['chatItem', 'isMine'], data() { return { emojiMap: emojiMap, emojiUrl: emojiUrl, } }, computed: { // contentList() { // return decodeText(this.chatItem) // }, // Timestamp processing date () { return getFullDate(new Date(this.chatItem.time * 1000)) }, } } </script> <style scoped> .text-element-wrapper { position: relative; max-width: 360px; border-radius: 3px; word-break: break-word; border: 1px solid rgb(235, 235, 235); } .text-element { padding: 6px; } .element-received { max-width: 280px; background-color: #fff; float: right; } .received-img { float: left; padding-right: 6px; } .element-send { max-width: 280px; background: rgb(5, 185, 240); float: left; } .send-img { float: right; } </style> The main idea of sending emoticons in the vue interface is: <template> <section class="dialogue-section clearfix" > <div class="row clearfix" v-for="(item,index) in msgs" :key = index> <img :src="item.uid == myInfo.uid ? myInfo.avatar :otherInfo.avatar" :class="item.uid == myInfo.uid ? 'headerleft' : 'headerright'"> <p :class="item.uid == myInfo.uid ? 'textleft' : 'textright'" v-html="customEmoji(item.content)"></p> </div> </section> <div id="emoji-list" class="flex-column" v-if="emojiShow"> //First, use this to determine whether the emoji pop-up window should appear<div class="flex-cell flex-row" v-for="list in imgs"> <div class="flex-cell flex-row cell" v-for="item in list" @click="inputEmoji(item)"> <img :src="'./emoji/' + item + '.png'"> </div> </div> </div> </template> <script> import { sendMsg } from "@/ws"; //This is a long connection import _ from "lodash"; //This is a very powerful library in js import eventBus from '@/eventBus' //This is a public file passed between child and parent console.log(emoji) export default { data() { this.imgs = _.chunk(emoji, 6) //This is to call the chunk method of the lodash library to divide the six elements into an array, which is just a two-dimensional array in the emoji array. return { emojiShow: false //At the beginning, the click button is not displayed by default. To display the click button, you can write @click='emojiShow=emojiShow'}; }, methods: { customEmoji(text) { //This function is used by the server to convert the passed name into an image. return text.replace(/\[([A-Za-z0-9_]+)\]/g, '<img src="./emoji/$1.png" style="width:30px; height:30px;">') }, inputEmoji(pic) { this.content += `[${pic}]` //The passed name is converted to a picture} }; </script> <style scoped> @import '../../assets/css/dialogue.css'; #emoji-list { height: 230px; background: #fff; } #emoji-list .cell { line-height: 13vh; border-right: 1rpx solid #ddd; border-bottom: 1rpx solid #ddd; } .flex-row { display: flex; flex-direction: row; justify-content: center; align-items: center; } .flex-column { display: flex; flex-direction: column; justify-content: center; align-items: stretch; } .flex-cell { flex: 1; } .cell img { width: 35px; height: 35px; } </style> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed steps for adding hosts you need to monitor in zabbix
>>: Solution to ONLY_FULL_GROUP_BY error in Mysql5.7 and above
Tomcat is an HTTP server that is the official ref...
This article example shares the specific code of ...
Before webpack packaging, we must ensure that the...
This article example shares the specific code of ...
Table of contents 1. Installation 2. Use Echarts ...
When I installed php56 with brew on mac , I encou...
The following operation demonstrations are all ba...
ClickHouse is an open source column-oriented DBMS...
Transactional Characteristics 1. Atomicity: After...
Preface A reverse proxy is a server that receives...
I downloaded and installed the latest version of ...
In the process of making web pages, it is inevita...
Table of contents question Reproduction Implicit ...
1. The first method is to start the local tomcat ...
Recently, I need to package the project for membe...