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. PAT L2-001 紧急救援 —— (多参数最短路)

    和天梯中的直捣黄龙差不多.但是,通过这个问题,我对多参数最短路又有了更深一层的了解. 这题因为点数比较多,所以如果直接用大力学长的在G上dfs找最短路径的条数的话,会TLE,所以需要剪枝.剪枝方法是, ...

  2. Android学习——MediaProvider与Music模块

    一.MediaProvider数据库介绍 1. 关系型数据库 关系模型的物理表示是一个二维表格,由行和列组成. 2. MediaProvider数据库存储位置     /data/data/com.a ...

  3. dubbo学习笔记(一)超时与重试

    dubbo提供在provider和consumer端,都提供了超时(timeout)和重试(retries)的参数配置. 配置方式 provider端在<dubbo:service>中配置 ...

  4. other备忘

    wps CONCATENATE 只是因为格式 设置成了文本,把这列 格式 设置成 常规,双击下 结果就出来了 https://zhidao.baidu.com/question/21208668961 ...

  5. DataSet转换为实体类

    /// <summary> /// DataSet转换为实体类 /// </summary> /// <typeparam name="T">实 ...

  6. [java] 将整数在千分位或万分位以逗号分隔表示

    简单使用DecimalFormat的功能就能做到了,代码如下: package com.testEmp; import java.text.DecimalFormat; public class Nu ...

  7. 操作系统 | 结合 CPU 理解一行 Java 代码是怎么执行的

    根据冯·诺依曼思想,计算机采用二进制作为数制基础,必须包含:运算器.控制器.存储设备,以及输入输出设备,如下图所示. 我们先来分析 CPU 的工作原理,现代 CPU 芯片中大都集成了,控制单元,运算单 ...

  8. 使用pyinstaller 打包python程序

    1.打开PyCharm的Terminal,使用命令pip install pyinstaller安装pyinstaller 2.打包命令:pyinstaller --console --onefile ...

  9. acl设置问题

    在学习nfs服务配置的时候用到了acl规则(服务配置文件权限设置可写,但是由于客户端映射,不能写入,所以要设置系统权限),但是遇到了一个小小的问题:一.当使用-x选项取消规则的时候,再次查看权限后面仍 ...

  10. ObjectAnimator属性动画示例代码

    import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.app.Ac ...