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
Let’s look at the effect first: This effect looks...
drop table Drop directly deletes table informatio...
Table of contents I. Overview 2. pt-archiver main...
When installing Tomcat in Docker, Tomcat may over...
To achieve CSS screen size adaptation, we must fi...
This article records the method of sharing files ...
Table of contents 1. The difference between trans...
MySQL5.7.21 installation and password setting tut...
Install crontab yum install crontabs CentOS 7 com...
Serve: # chkconfig --list List all system service...
In the table header, you can define the dark bord...
Docker virtualizes a bridge on the host machine. ...
Writing XHTML demands a clean HTML syntax. Writing...
question When we are developing normally, if we w...
This article uses examples to illustrate the prin...