VUE表情包输入组件,先来张成品图看看。



年底了没事干,把以前做过的项目中的组件拿出来再复习一下, 先说说思路吧。

注意:

1. 项目是用vue-cli3.0搭建起来的项目, 参考cli3.0官网地址

2.样式是用scss需要安装依赖: npm install node-sass sass-loader -D

思路: 页面内容总体分为三块区域(内容区,表情区,输入区),引入JSON文件表情库渲染到页面,给每个表情绑定点击事件并传递下标,将用户点击过的表情存放到一个数组中,赋值给input标签的value中让其显示先输入框内,然后给 确定 按钮绑定点击事件,用户点击确定按钮将input中的value值赋值给内容区(内容去也要创建一个数组)让其渲染到你要的位置上,这样就完成了表情的渲染和发送。

html区域


<template>
<div class="home">
<!-- 页面内容区域 -->
<div :class="faceShow ? 'contentBox contFaceShow' : 'contentBox'">
<ul>
<li v-for="(item,index) in content" :key="index">
<span>{{item}}</span>
</li>
</ul>
</div>
<!-- 输入框区域 -->
<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>
<!-- 表情区域 -->
<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区域


// 导入JSON格式的表情库
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 = [];
}
},
// 获取用户点击之后的标签 ,存放到输入框内
getBrow(index) {
for (let i in this.faceList) {
if (index == i) {
this.getBrowString = this.faceList[index];
this.textConent += this.getBrowString;
}
}
},
// 将input的内容渲染到页面上
referContent() {
if (this.textConent == "") return alert("请输入内容");
// 存入
this.content.push(this.textConent);
// 清空input数据
this.textConent = "";
// 关闭表情列表
this.faceShow = false;
}
},
};

css区域


<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地址https://github.com/wanglei-bilibili/Vue-WeiXin-face

欢迎大家来提出意见,共同努力进步。

来源:https://blog.csdn.net/qq_37141008/article/details/86528345

Vue 表情输入组件,微信face表情组件的更多相关文章

  1. 【腾讯Bugly干货分享】打造“微信小程序”组件化开发框架

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/2nQzsuqq7Avgs8wsRizUhw 作者:Gc ...

  2. Vue(基础八)_导航守卫(组件内的守卫)

    一.前言 主要通过一个例子演示三个钩子的作用: 1.beforeRouteEnter()                                                         ...

  3. vue构造函数(根实例化时和组件实例对象选项)参数:选项详解

    实例选项(即传给构造函数的options):数据,DOM,生命周期钩子函数,资源,组合,其他 数据 data 属性能够响应数据变化,当这些数据改变时,视图会进行重渲染. 访问方式: 1.通过 vm.$ ...

  4. 微信emoji表情编码 、MySQL 存储 emoji 表情符号字符集

    相关资料 微信emoji表情编码 微信用户名显示「emoji表情」 PHP处理微信中带Emoji表情的消息发送和接收(Unicode字符转码编码) MySQL 存储emoji表情 MySQL 存储 e ...

  5. 微信小程序组件化实践

    Do Not Repeat Yourself 如何提高代码质量,方法有许多:抽象.模块.组件化,我认为它们的中心点都是--Do Not Repeat Yourself. 小程序组件化 我们先看看小程序 ...

  6. Vue(2)- v-model、局部组件和全局组件、父子组件传值、平行组件传值

    一.表单输入绑定(v-model 指令) 可以用 v-model 指令在表单 <input>.<textarea> 及 <select> 元素上创建双向数据绑定. ...

  7. Vue.js学习笔记 第八篇 组件

    全局注册组件 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <ti ...

  8. Vue.js基础语法(二)组件

    vue学习的一系列,全部来自于表哥---表严肃,是我遇到过的讲课最通透,英文发音最好听的老师,想一起听课就去这里吧 https://biaoyansu.com/i/hzhj1206 把一段经常要用的东 ...

  9. Vue 2 --v-model、局部组件和全局组件、父子组件传值、平行组件传值

    一.表单输入绑定(v-model 指令) 可以用 v-model 指令在表单 <input>.<textarea> 及 <select> 元素上创建双向数据绑定. ...

  10. js replace 全局替换 以表单的方式提交参数 判断是否为ie浏览器 将jquery.qqFace.js表情转换成微信的字符码 手机端省市区联动 新字体引用本地运行可以获得,放到服务器上报404 C#提取html中的汉字 MVC几种找不到资源的解决方式 使用Windows服务定时去执行一个方法的三种方式

    js replace 全局替换   js 的replace 默认替换只替换第一个匹配的字符,如果字符串有超过两个以上的对应字符就无法进行替换,这时候就要进行一点操作,进行全部替换. <scrip ...

随机推荐

  1. vue-router的两种动态路由

    第一种实质上不能算动态路由,充其量算是参数的传递 https://www.jianshu.com/p/f499d9f64958 第二种是真正的动态路由,利用 router.addRoutes()设置动 ...

  2. 执行jar包或执行其中的某个类

    执行jar包,默认执行javafile中指定的main程序java -jar jar包例如 java -jar test.jar执行依赖其他jar包的class: java -cp .;E:\tool ...

  3. Leetcode题目155.最小栈(简单)

    题目描述: 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中.pop() -- 删除栈顶的元素.top() -- 获取栈顶 ...

  4. Ajax传递复杂对象报415

    特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...

  5. Process.Net

    ProcessSharp的构造函数,对应的测试是 https://github.com/lolp1/Process.NET/blob/master/test/Process.NET.Test/Core ...

  6. dev exception 2018

    java.lang.IllegalArgumentException: Circular placeholder reference 'trace.enable' in property defini ...

  7. JS 省市联动 ajax

    省市联动 //省市联动     $('.locationCode').change(function () {         var val = $(this).val();         if ...

  8. Mac系统下,docker安装nextcloud,打造个人本地网盘

    1.安装docker 推荐下载地址:http://get.daocloud.io/#install-docker-for-mac-windows   2.拉取镜像 $ docker pull next ...

  9. TCP怎么保证证包有序传输的,TCP的慢启动,拥塞避免,快速重传,快速恢复

    TCP提供了最可靠的数据传输,它给发送的每个数据包做顺序化(这看起来非常烦琐),然而,如果TCP没有这样烦琐的操作,那么,可能会造成更多的麻烦.如造成数据包的重传.顺序的颠倒甚至造成数据包的丢失. 那 ...

  10. 10.service 详解

    10.service 详解 什么是service:Kubernetes中的Service 是一个抽象的概念,它定义了Pod的逻辑分组和一种可以访问它们的策略,这组Pod能被Service访问,使用YA ...