All Projects → rishiqing → Vue Emoji

rishiqing / Vue Emoji

Licence: mit
An emoji component for vue2.0

Projects that are alternatives of or similar to Vue Emoji

Everyone
🍊Ant Design UI library for Vuejs 2.0
Stars: ✭ 38 (-2.56%)
Mutual labels:  vue-components, vue2
Vue Share Buttons
🔗A set of social buttons for Vue.js
Stars: ✭ 34 (-12.82%)
Mutual labels:  vue-components, vue2
Vue Gl
Vue.js components rendering 3D WebGL graphics reactively with three.js
Stars: ✭ 434 (+1012.82%)
Mutual labels:  vue-components, vue2
Vue Framework Wz
👏vue后台管理框架👏
Stars: ✭ 3,757 (+9533.33%)
Mutual labels:  vue-components, vue2
Vue Snotify
Vuejs 2 Notification Center
Stars: ✭ 755 (+1835.9%)
Mutual labels:  vue-components, vue2
Vue Video Player
🎞 @videojs component for @vuejs
Stars: ✭ 4,026 (+10223.08%)
Mutual labels:  vue-components, vue2
Vuelayers
Web map Vue components with the power of OpenLayers
Stars: ✭ 532 (+1264.1%)
Mutual labels:  vue-components, vue2
V Offline
🔌 Simple VueJS component to detect offline & online changes.
Stars: ✭ 307 (+687.18%)
Mutual labels:  vue-components, vue2
Vuejs Paginate
A Vue.js(v2.x+) component for creating pagination.
Stars: ✭ 697 (+1687.18%)
Mutual labels:  vue-components, vue2
Atui
A Vue.js 2.0 UI Toolkit for Web
Stars: ✭ 674 (+1628.21%)
Mutual labels:  vue-components, vue2
Quasar
Quasar Framework - Build high-performance VueJS user interfaces in record time
Stars: ✭ 20,090 (+51412.82%)
Mutual labels:  vue-components, vue2
Fish Ui
A Vue.js 2.0 UI Toolkit for Web
Stars: ✭ 861 (+2107.69%)
Mutual labels:  vue-components, vue2
Vux
Mobile UI Components based on Vue & WeUI
Stars: ✭ 17,573 (+44958.97%)
Mutual labels:  vue-components, vue2
Vue2
【🔥Vue.js资讯📚】目前web前端开发非常火爆的框架;定时更新,欢迎 Star 一下。
Stars: ✭ 395 (+912.82%)
Mutual labels:  vue-components, vue2
Vue Awesome Mui
🏆Mui component for Vue.js(1.x ~ 2.x)
Stars: ✭ 307 (+687.18%)
Mutual labels:  vue-components, vue2
Vue Touch Ripple
👆 Touch ripple component for @vuejs
Stars: ✭ 443 (+1035.9%)
Mutual labels:  vue-components, vue2
Vue Cnodejs
基于vue.js重写Cnodejs.org社区的webapp
Stars: ✭ 3,065 (+7758.97%)
Mutual labels:  vue-components, vue2
Vuenut
⚙️ Developer tools for vue js (Vuex)
Stars: ✭ 305 (+682.05%)
Mutual labels:  vue-components, vue2
Vuesax
New Framework Components for Vue.js 2
Stars: ✭ 5,293 (+13471.79%)
Mutual labels:  vue-components, vue2
Vue Quill Editor
🍡@quilljs editor component for @vuejs
Stars: ✭ 6,874 (+17525.64%)
Mutual labels:  vue-components, vue2

vue-emoji

Build Status Downloads Version License

基于 Vue2.0 的emoji插件

English

Vue-emoji

安装

yarn add rui-vue-emoji

使用示例

<link rel="stylesheet" type="text/css" href="./node_modules/vue-emoji-component/dist/vue-emoji.css">
<script src = './vue.min.js'></script>
<script src = './node_modules/vue-emoji-component/dist/vue-emoji.js'></script>
<div id="app">
  <div>
    <h1>Vue-Emoji</h1>
    <div contenteditable="" ref = 'edit' focus></div>
    <button ref = 'btn' @click = 'showEmoji = !showEmoji'>emoji</button>
    <vue-emoji
      v-show = 'showEmoji'
      ref = 'emoji'
      @select = 'showEmoji = false'
      @hide = 'handleHide'
    ></vue-emoji>
  </div>
</div>
new Vue({
  el: '#app',
  components: {
    VueEmoji
  },
  data () {
    return {
      showEmoji : false
    }
  },
  mounted () {
    this.$refs.emoji.appendTo({
      area: this.$refs.edit,
      btn: this.$refs.btn,
      position: 'top left'
    });
  },
  methods: {
    hide () {
      this.showEmoji = false;
    },
    handleHide (e) {
      this.hide();
    }
  }
});

webpack中引入

// styles.js
import 'rui-vue-emoji/dist/vue-emoji.css';

你也可以考虑将雪碧图和单个图标上传到CDN, 那么需要改动一下jscss文件。

[class*="sprite-"] {
  background-image: url("https://your.cdn.path/")!important;
}
mounted () {
  this.$refs.emoji.appendTo({
    area: this.$refs.edit,
    btn: this.$refs.btn,
    position: 'top left'
  }).setPath('https://your.cdn.path/');
},

需要注意的是, 在css中控制雪碧图的路径, 在js中控制最后引用的单个表情图片的路径。

选项

事件

  • select: 选中表情时会触发此事件, 事件参数为选中的表情对应的图片
  • hide: 触发隐藏事件, 当发生这个事件后, 需要在父组件中对弹窗进行关闭, 含有一个事件对象, 表示点击的元素。

方法

appendTo

这个方法需要在父组件mounted的是时候进行调用, 以便初始化参数。 至少需要传递两个参数area以及btn, area表示需要将表情插入的地方, btn表示触发表情弹窗显示的按钮。 可选的position选项用于设置表情框的位置, 默认为top center, 表示在位于按钮的上方, 居中显示。 当第一个参数不为top的时候, 将会置于按钮下方。 第二个参数表示弹窗相对于按钮的位置, 可选的有left, center, right三个选项。

calcPosition

用于重新计算弹窗的位置, 当[contenteditable]内容增加的情况下, 通常其高度也会变化, 这个时候需要重新进行计算以更新弹窗的位置。 遗憾的是, 我没能找到一种自动监听其变化的方法, 所以需要手动监听, 然后再进行调用。

app.vue

watch: {
  showEmoji (value) { // showEmoji 为控制弹窗隐藏显示的属性。
    if (value) {
      this.$refs.emoji.calcPosition();
    }
  }
}

getImgPathByUnicode

该方法接收一个表情编码, 如果能够找到对应的图片, 则会返回基于前面设定的路径的图片, 如果没有找到, 则会返回null。

<vue-emoji
  v-show = 'showEmoji'
  ref = 'emoji'
  :unicode='true'
  @select = 'handleSelect'
  @hide = 'hide()'
></vue-emoji>
handleSelect (img) {
  if (img.nodeType === 3) {
    var $img = new Image();
    $img.src =  this.$refs.emoji.getImgPathByUnicode(img.textContent);
    $app1.appendChild($img);
  }
  this.hide();
}

getUnicodeByImgPath

该方法接受一个图片地址, 返回对应的unicode编码的表情

setPath

用于指定所需使用的图片的地址路径。 默认为当前根目录下的images/, 推荐使用CDN.

属性

unicode

默认情况下当选中一个表情的时候会以图片的方式插入对应区域。你可以通过配置unicode选项来开启Unicode支持, 也就是说, 在这种情况下, 选中一个表情的时候, 会插入对应的Unicode字符。需要注意的是, 相比于图片模式, 使用Unicode的时候会缺少一些表情。

<vue-emoji
  v-show = 'showEmoji'
  ref = 'emoji'
  :unicode='true'
  @select = 'hide()'
  @hide = 'hide()'
></vue-emoji>

captions

默认情况下, 会使用表情、自然、物品、地点、符号来作为每个emoji栏目的标题, 可以通过使用组件的时候传入captions参数, 来改变标题文字。

<vue-emoji
  v-show = 'showEmoji'
  ref = 'emoji'
  :captions = 'captions'
  @select = 'showEmoji = false'
  @hide = 'handleHide'
></vue-emoji>
data () {
  return {
    captions: ['Expressions', 'Nature', 'Goods', 'Lacation', 'Symbol']
  }
}

开发

git clone [email protected]:rishiqing/vue-emoji.git
cd vue-emoji
yarn
npm start

一些小问题

因为接触Vue的时间比较短, 仓促之下做的这个东西也有太多不完善的地方。 比如我希望的是, 能够在template中就将元素的一些属性传递过去, 从而取代在mounted方法里面手动调用appendTo 的方式, 因为在我看来我现在的这种实现就是一个丑陋的hack, 然而当我多次尝试之后, 也没有找到一个能够在父组件中渲染子组件的时候, 向子组件里面传递父组件其他DOM节点的引用的方法。 当然, 也许更大的原因还是在于我设计上的失误。所以, 如果你有更好的方法, 欢迎告诉我, 在下不胜感激。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].