您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)Vue中怎么實(shí)現(xiàn)一個(gè)表情輸入組件,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
html區(qū)域
<template> <div class="home"> <!-- 頁(yè)面內(nèi)容區(qū)域 --> <div :class="faceShow ? 'contentBox contFaceShow' : 'contentBox'"> <ul> <li v-for="(item,index) in content" :key="index"> <span>{{item}}</span> </li> </ul> </div> <!-- 輸入框區(qū)域 --> <div :class="faceShow ?'box boxFaceShow' : 'box'" ref="heightFace"> <input type="text" v-model="textConent" class="inputContent"> <button class="referBut" @click="referContent">提交</button> <button class="faceBut" @click="faceContent">表情</button> </div> <!-- 表情區(qū)域 --> <div class="browBox" v-if="faceShow"> <ul> <li v-for="(item,index) in faceList" :key="index" @click="getBrow(index)">{{item}}</li> </ul> </div> </div> </template>
JS區(qū)域
// 導(dǎo)入JSON格式的表情庫(kù) const appData = require("@/assets/emojis.json"); export default { name: "home", data() { return { textConent: "", faceList: [], faceShow: false, getBrowString: "", content: [] }; }, methods: { // 表情 faceContent() { this.faceShow = !this.faceShow; if (this.faceShow == true) { for (let i in appData) { this.faceList.push(appData[i].char); } } else { this.faceList = []; } }, // 獲取用戶(hù)點(diǎn)擊之后的標(biāo)簽 ,存放到輸入框內(nèi) getBrow(index) { for (let i in this.faceList) { if (index == i) { this.getBrowString = this.faceList[index]; this.textConent += this.getBrowString; } } }, // 將input的內(nèi)容渲染到頁(yè)面上 referContent() { if (this.textConent == "") return alert("請(qǐng)輸入內(nèi)容"); // 存入 this.content.push(this.textConent); // 清空input數(shù)據(jù) this.textConent = ""; // 關(guān)閉表情列表 this.faceShow = false; } }, };
css區(qū)域
<style lang="scss" scoped> body, html, head, .home { width: 100%; height: 100%; padding: 0px; position: relative; margin: 0px; } .home { width: 100%; height: 100%; .contentBox { width: 100%; display: flex; flex-direction: column; justify-content: flex-end; text-align: right; position: absolute; bottom: 60px; li { list-style: none; padding: 4px 10px; margin-bottom: 20px; span { background: #e6e6e6; border-radius: 5px; padding: 5px; } } } .contFaceShow { position: absolute; bottom: 240px; } .box { width: 100%; height: 40px; margin: auto; position: absolute; bottom: 0px; .inputContent { position: absolute; bottom: 0%; left: 0%; width: 74%; height: 100%; border: 1px solid #ccc; } .referBut { position: absolute; bottom: 0%; right: 2%; height: 100%; width: 10%; border-radius: 5px; background: #aaaaff; color: #fff; } .faceBut { position: absolute; bottom: 0; right: 13%; height: 100%; width: 10%; border-radius: 5px; background: #aaaaff; color: #fff; } } .boxFaceShow { position: absolute; bottom: 200px !important; } .browBox { width: 100%; height: 200px; background: #e6e6e6; position: absolute; bottom: 0px; overflow: scroll; ul { display: flex; flex-wrap: wrap; padding: 10px; li { width: 14%; font-size: 26px; list-style: none; text-align: center; } } } } </style> <style lang="scss"> body, html, head { width: 100%; height: 100%; position: relative; } #app { height: 100%; } * { padding: 0px; margin: 0px; } </style>
關(guān)于Vue中怎么實(shí)現(xiàn)一個(gè)表情輸入組件就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。