Vue表情輸入組件 微信face表情組件
VUE表情包輸入組件,先來(lái)張成品圖看看。

年底了沒(méi)事干,把以前做過(guò)的項(xiàng)目中的組件拿出來(lái)再?gòu)?fù)習(xí)一下, 先說(shuō)說(shuō)思路吧。
注意:
1. 項(xiàng)目是用vue-cli3.0搭建起來(lái)的項(xiàng)目, 參考cli3.0官網(wǎng)地址
2.樣式是用scss需要安裝依賴: npm install node-sass sass-loader -D
思路: 頁(yè)面內(nèi)容總體分為三塊區(qū)域(內(nèi)容區(qū),表情區(qū),輸入?yún)^(qū)),引入JSON文件表情庫(kù)渲染到頁(yè)面,給每個(gè)表情綁定點(diǎn)擊事件并傳遞下標(biāo),將用戶點(diǎn)擊過(guò)的表情存放到一個(gè)數(shù)組中,賦值給input標(biāo)簽的value中讓其顯示先輸入框內(nèi),然后給 確定 按鈕綁定點(diǎn)擊事件,用戶點(diǎn)擊確定按鈕將input中的value值賦值給內(nèi)容區(qū)(內(nèi)容去也要?jiǎng)?chuàng)建一個(gè)數(shù)組)讓其渲染到你要的位置上,這樣就完成了表情的渲染和發(fā)送。
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 = [];
}
},
// 獲取用戶點(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>
代碼在我的github上:github地址
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue實(shí)現(xiàn)驗(yàn)證碼輸入框組件
- vue組件中點(diǎn)擊按鈕后修改輸入框的狀態(tài)實(shí)例代碼
- Vue 表情包輸入組件的實(shí)現(xiàn)代碼
- 基于Vue開(kāi)發(fā)數(shù)字輸入框組件
- 基于elementUI使用v-model實(shí)現(xiàn)經(jīng)緯度輸入的vue組件
- vue實(shí)現(xiàn)一個(gè)6個(gè)輸入框的驗(yàn)證碼輸入組件功能的實(shí)例代碼
- Vue數(shù)字輸入框組件的使用方法
- Vue.js自定義事件的表單輸入組件方法
- 說(shuō)說(shuō)如何在Vue.js中實(shí)現(xiàn)數(shù)字輸入組件的方法
- vue車(chē)牌輸入組件使用方法詳解
相關(guān)文章
vue?element-ui的table列表中展示多張圖片(可放大)效果實(shí)例
這篇文章主要給大家介紹了關(guān)于vue?element-ui的table列表中展示多張圖片(可放大)效果的相關(guān)資料,文中通過(guò)代碼示例介紹的非常詳細(xì),需要的朋友可以參考下2023-08-08
關(guān)于在vue2中使用weixin-js-sdk的詳細(xì)步驟
公司最近有微信公眾號(hào)的需求,那么微信登錄授權(quán)和如何使用WX-JSSDk實(shí)現(xiàn)分享等等肯定是最頭疼的問(wèn)題,這篇文章主要給大家介紹了關(guān)于在vue2中使用weixin-js-sdk的詳細(xì)步驟,需要的朋友可以參考下2024-07-07
Vue.js Ajax動(dòng)態(tài)參數(shù)與列表顯示實(shí)現(xiàn)方法
Vue.js是一個(gè)輕巧、高性能、可組件化的MVVM庫(kù),同時(shí)擁有非常容易上手的API。下面通過(guò)本文給大家介紹vue.js ajax動(dòng)態(tài)參數(shù)與列表顯示實(shí)現(xiàn)方法,感興趣的朋友一起看看吧2016-10-10
vue-i18n結(jié)合Element-ui的配置方法
這篇文章主要介紹了vue-i18n結(jié)合Element-ui的配置方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05
vue如何動(dòng)態(tài)生成andv圖標(biāo)
這篇文章主要介紹了vue如何動(dòng)態(tài)生成andv圖標(biāo)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
Vue標(biāo)簽屬性動(dòng)態(tài)傳參并拼接字符串的操作方法
這篇文章主要介紹了Vue標(biāo)簽屬性動(dòng)態(tài)傳參并拼接字符串的操作方法,我們需要根據(jù)傳入值的類型,在placeholder屬性賦值"請(qǐng)輸入長(zhǎng)度",“請(qǐng)輸入寬度”,"請(qǐng)輸入厚度"等提示字符,本文通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友參考下吧2023-11-11
vue3模塊創(chuàng)建runtime-dom源碼解析
這篇文章主要為大家介紹了vue3模塊創(chuàng)建runtime-dom源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
vue 動(dòng)態(tài)改變靜態(tài)圖片以及請(qǐng)求網(wǎng)絡(luò)圖片的實(shí)現(xiàn)方法
下面小編就為大家分享一篇vue 動(dòng)態(tài)改變靜態(tài)圖片以及請(qǐng)求網(wǎng)絡(luò)圖片的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
python虛擬環(huán)境 virtualenv的簡(jiǎn)單使用
virtualenv是一個(gè)創(chuàng)建隔絕的Python環(huán)境的工具。這篇文章主要介紹了python虛擬環(huán)境 virtualenv的簡(jiǎn)單使用,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01
vue2 如何實(shí)現(xiàn)div contenteditable=“true”(類似于v-model)的效果
這篇文章主要給大家介紹了利用vue2如何實(shí)現(xiàn)div contenteditable="true",就是類似于v-model的效果,文中給出了兩種解決的思路,對(duì)大家具有一定的參考價(jià)值,有需要的朋友們下面來(lái)一起看看吧。2017-02-02

