欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue界面發(fā)送表情的實(shí)現(xiàn)代碼

 更新時(shí)間:2020年09月11日 12:37:40   作者:前端阿龍  
這篇文章主要介紹了vue界面發(fā)送表情的實(shí)現(xiàn)代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

完全照搬不一定能寫出來(lái) 只是讓看個(gè)思想

<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"> //首先根據(jù)這個(gè)來(lái)判斷發(fā)送表情彈窗用不用出現(xiàn)
       <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"; //是一個(gè)長(zhǎng)連接
import _ from "lodash";//這個(gè)是js一個(gè)很強(qiáng)大的庫(kù) 
import eventBus from '@/eventBus'//這是一個(gè)子父?jìng)鬟f的公共文件
console.log(emoji)
export default {
 data() {
  this.imgs = _.chunk(emoji, 6) //這個(gè)是調(diào)用lodash庫(kù)的chunk方法 把 六個(gè)元素分成一個(gè)數(shù)組只不過(guò)是emoji這個(gè)數(shù)組中的二維數(shù)組
  return {
   emojiShow: false //剛開(kāi)始默認(rèn)不顯示 點(diǎn)擊按鈕顯示 點(diǎn)擊的按鈕上可以寫@click='emojiShow=emojiShow'這種寫法
  };
 },
 methods: {
  customEmoji(text) { //這個(gè)函數(shù)就是服務(wù)器端把傳過(guò)來(lái)的名稱轉(zhuǎn)化為圖片的
   return text.replace(/\[([A-Za-z0-9_]+)\]/g, '<img src="./emoji/$1.png" style="width:30px; height:30px;">')
  },
  inputEmoji(pic) {
   this.content += `[${pic}]`//傳過(guò)來(lái)的名字轉(zhuǎn)為圖片
  }
};
</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>

補(bǔ)充知識(shí):vue+element-ui實(shí)現(xiàn)聊天表情包

我是用的本地json數(shù)據(jù)實(shí)現(xiàn)的,表情不是很多,首先創(chuàng)建個(gè)json文件,代碼如下:

[{
  "codes": "1F600",
  "char": "😀",
  "name": "grinning face"
 },
 {
  "codes": "1F603",
  "char": "😃",
  "name": "grinning face with big eyes"
 },
 {
  "codes": "1F604",
  "char": "😄",
  "name": "grinning face with smiling eyes"
 },
 {
  "codes": "1F601",
  "char": "😁",
  "name": "beaming face with smiling eyes"
 },
 {
  "codes": "1F606",
  "char": "😆",
  "name": "grinning squinting face"
 },
 {
  "codes": "1F605",
  "char": "😅",
  "name": "grinning face with sweat"
 },
 {
  "codes": "1F923",
  "char": "🤣",
  "name": "rolling on the floor laughing"
 },
 {
  "codes": "1F602",
  "char": "😂",
  "name": "face with tears of joy"
 },
 {
  "codes": "1F642",
  "char": "🙂",
  "name": "slightly smiling face"
 },
 {
  "codes": "1F643",
  "char": "🙃",
  "name": "upside-down face"
 },
 {
  "codes": "1F609",
  "char": "😉",
  "name": "winking face"
 },
 {
  "codes": "1F60A",
  "char": "😊",
  "name": "smiling face with smiling eyes"
 },
 {
  "codes": "1F607",
  "char": "😇",
  "name": "smiling face with halo"
 },
 {
  "codes": "1F970",
  "char": "🥰",
  "name": "smiling face with hearts"
 },
 {
  "codes": "1F60D",
  "char": "😍",
  "name": "smiling face with heart-eyes"
 },
 {
  "codes": "1F929",
  "char": "🤩",
  "name": "star-struck"
 },
 {
  "codes": "1F618",
  "char": "😘",
  "name": "face blowing a kiss"
 },
 {
  "codes": "1F617",
  "char": "😗",
  "name": "kissing face"
 },
 {
  "codes": "1F61A",
  "char": "😚",
  "name": "kissing face with closed eyes"
 },
 {
  "codes": "1F619",
  "char": "😙",
  "name": "kissing face with smiling eyes"
 },
 {
  "codes": "1F44B",
  "char": "👋",
  "name": "waving hand"
 },
 {
  "codes": "1F91A",
  "char": "🤚",
  "name": "raised back of hand"
 },
 {
  "codes": "1F590",
  "char": "🖐",
  "name": "hand with fingers splayed"
 },
 {
  "codes": "270B",
  "char": "✋",
  "name": "raised hand"
 },
 {
  "codes": "1F596",
  "char": "🖖",
  "name": "vulcan salute"
 },
 {
  "codes": "1F44C",
  "char": "👌",
  "name": "OK hand"
 },
 {
  "codes": "1F90F",
  "char": "🤏",
  "name": "pinching hand"
 },
 {
  "codes": "270C",
  "char": "✌",
  "name": "victory hand"
 },
 {
  "codes": "1F91E",
  "char": "🤞",
  "name": "crossed fingers"
 },
 {
  "codes": "1F91F",
  "char": "🤟",
  "name": "love-you gesture"
 },
 {
  "codes": "1F918",
  "char": "🤘",
  "name": "sign of the horns"
 },
 {
  "codes": "1F919",
  "char": "🤙",
  "name": "call me hand"
 },
 {
  "codes": "1F448",
  "char": "👈",
  "name": "backhand index pointing left"
 },
 {
  "codes": "1F449",
  "char": "👉",
  "name": "backhand index pointing right"
 },
 {
  "codes": "1F446",
  "char": "👆",
  "name": "backhand index pointing up"
 },
 {
  "codes": "1F595",
  "char": "🖕",
  "name": "middle finger"
 },
 {
  "codes": "1F447",
  "char": "👇",
  "name": "backhand index pointing down"
 },
 {
  "codes": "261D FE0F",
  "char": "☝️",
  "name": "index pointing up"
 },
 {
  "codes": "1F44D",
  "char": "👍",
  "name": "thumbs up"
 },
 {
  "codes": "1F44E",
  "char": "👎",
  "name": "thumbs down"
 },
 {
  "codes": "270A",
  "char": "✊",
  "name": "raised fist"
 },
 {
  "codes": "1F44A",
  "char": "👊",
  "name": "oncoming fist"
 },
 {
  "codes": "1F91B",
  "char": "🤛",
  "name": "left-facing fist"
 },
 {
  "codes": "1F91C",
  "char": "🤜",
  "name": "right-facing fist"
 }

]

vue組件中代碼直接貼出來(lái),廢話不多說(shuō):

<template>
 <div class="chatIcon">
  <el-popover
   placement="top-start"
   width="400"
   trigger="click"
   class="emoBox"
  >
   <div class="emotionList">
    <a
     href="javascript:void(0);" rel="external nofollow" 
     @click="getEmo(index)"
     v-for="(item, index) in faceList"
     :key="index"
     class="emotionItem"
     >{{ item }}</a
    >
   </div>
   <el-button
    class="emotionSelect"
    icon="iconfont icon-biaoqing"
    slot="reference"
   ></el-button>
  </el-popover>
  <el-input
   v-model="textarea"
   class="chatText"
   resize="none"
   type="textarea"
   id="textarea"
   rows="5"
   @keyup.enter.native="sendInfo"
  ></el-input>
 </div>
</template>
<script>
const appData = require("@/utils/emoji.json");
export default {
 mounted() {
  for (let i in appData) {
   this.faceList.push(appData[i].char);
  }
 },
 data() {
  return {
   faceList: [],
   textarea: ""
  };
 },
 methods: {
  getEmo(index) {
   var textArea = document.getElementById("textarea");
   function changeSelectedText(obj, str) {
    if (window.getSelection) {
     // 非IE瀏覽器
     textArea.setRangeText(str);
     // 在未選中文本的情況下,重新設(shè)置光標(biāo)位置
     textArea.selectionStart += str.length;
     textArea.focus();
    } else if (document.selection) {
     // IE瀏覽器
     obj.focus();
     var sel = document.selection.createRange();
     sel.text = str;
    }
   }
   changeSelectedText(textArea, this.faceList[index]);
   this.textarea = textArea.value; // 要同步data中的數(shù)據(jù)
   // console.log(this.faceList[index]);
   return;
  }
 }
};
</script>

<style lang="scss">
/* el-popover是和app同級(jí)的,所以scoped的局部屬性設(shè)置了無(wú)效 */
/* 需要設(shè)置全局style */
.el-popover {
 height: 200px;
 width: 400px;
 overflow: scroll;
 overflow-x: auto;
}
</style>

<style scoped>
.chatIcon {
 padding: 0 10px;
 font-size: 25px;
}
.emotionList {
 display: flex;
 flex-wrap: wrap;
 padding: 5px;
}
.emotionItem {
 width: 10%;
 font-size: 20px;
 text-align: center;
}
/*包含以下四種的鏈接*/
.emotionItem {
 text-decoration: none;
}
/*正常的未被訪問(wèn)過(guò)的鏈接*/
.emotionItem:link {
 text-decoration: none;
}
/*已經(jīng)訪問(wèn)過(guò)的鏈接*/
.emotionItem:visited {
 text-decoration: none;
}
/*鼠標(biāo)劃過(guò)(停留)的鏈接*/
.emotionItem:hover {
 text-decoration: none;
}
/* 正在點(diǎn)擊的鏈接*/
.emotionItem:active {
 text-decoration: none;
}
</style>

以上這篇vue界面發(fā)送表情的實(shí)現(xiàn)代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue.js iview打包上線后字體圖標(biāo)不顯示解決辦法

    vue.js iview打包上線后字體圖標(biāo)不顯示解決辦法

    這篇文章主要介紹了vue.js iview打包上線后字體圖標(biāo)不顯示解決辦法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • vue實(shí)現(xiàn)虛擬滾動(dòng)渲染成千上萬(wàn)條數(shù)據(jù)

    vue實(shí)現(xiàn)虛擬滾動(dòng)渲染成千上萬(wàn)條數(shù)據(jù)

    本文主要介紹了vue實(shí)現(xiàn)虛擬滾動(dòng)渲染成千上萬(wàn)條數(shù)據(jù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • Vue中使用的EventBus有生命周期

    Vue中使用的EventBus有生命周期

    這篇文章主要介紹了Vue中使用的EventBus有生命周期的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-07-07
  • vite+vue3項(xiàng)目解決低版本兼容性問(wèn)題解決方案(Safari白屏)

    vite+vue3項(xiàng)目解決低版本兼容性問(wèn)題解決方案(Safari白屏)

    這篇文章主要介紹了vite+vue3項(xiàng)目解決低版本兼容性問(wèn)題(Safari白屏),使用官方插件 @vitejs/plugin-legacy 為打包后的文件提供傳統(tǒng)瀏覽器兼容性支持,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2024-03-03
  • vue手寫<RouterLink/>組件實(shí)現(xiàn)demo詳解

    vue手寫<RouterLink/>組件實(shí)現(xiàn)demo詳解

    這篇文章主要為大家介紹了vue手寫<RouterLink/>組件實(shí)現(xiàn)demo詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • ant-design-vue Table pagination分頁(yè)實(shí)現(xiàn)全過(guò)程

    ant-design-vue Table pagination分頁(yè)實(shí)現(xiàn)全過(guò)程

    這篇文章主要介紹了ant-design-vue Table pagination分頁(yè)實(shí)現(xiàn)全過(guò)程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Vue頁(yè)面首次載入優(yōu)化的全過(guò)程

    Vue頁(yè)面首次載入優(yōu)化的全過(guò)程

    凡是做SPA的項(xiàng)目,特別是移動(dòng)端的SAP項(xiàng)目,首屏加載速度必定是一個(gè)繞不過(guò)去的話題,下面這篇文章主要給大家介紹了關(guān)于Vue頁(yè)面首次載入優(yōu)化的相關(guān)資料,需要的朋友可以參考下
    2021-12-12
  • Vue2.x Todo之自定義指令實(shí)現(xiàn)自動(dòng)聚焦的方法

    Vue2.x Todo之自定義指令實(shí)現(xiàn)自動(dòng)聚焦的方法

    我們希望用戶雙擊 todo 進(jìn)入編輯狀態(tài)后輸入框自動(dòng)獲取焦點(diǎn),而不是需要先手動(dòng)點(diǎn)一下。這篇文章主要介紹了Vue 2.x Todo之自定義指令實(shí)現(xiàn)自動(dòng)聚焦,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2019-01-01
  • element-ui 中的table的列隱藏問(wèn)題解決

    element-ui 中的table的列隱藏問(wèn)題解決

    這篇文章主要介紹了element-ui 中的table的列隱藏問(wèn)題解決,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Vue3在jsx下父子組件實(shí)現(xiàn)使用插槽方式

    Vue3在jsx下父子組件實(shí)現(xiàn)使用插槽方式

    這篇文章主要介紹了Vue3在jsx下父子組件實(shí)現(xiàn)使用插槽方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10

最新評(píng)論