欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

一文教你如何在Vue項(xiàng)目中使用Emoji表情

 更新時(shí)間:2025年03月12日 10:10:09   作者:英子的搬磚日志  
這篇文章主要為大家詳細(xì)介紹了在vue項(xiàng)目中如何使用emoji表情,包括font-awesome圖標(biāo),v-emoji-picker,vue-emoji等emoji表情庫(kù),需要的可以參考下

主要介紹了在vue項(xiàng)目中,如何使用emoji表情,包括:font-awesome 圖標(biāo)、v-emoji-picker、vue-emoji等emoji表情庫(kù)。

1、直接使用html的 Emoji 字符集

使用:

<template>
	<p style="font-size:20px">&#128512;</p>
    <p>十進(jìn)制:&#128512;</p>
    <p>十六進(jìn)制:&#x1F600;</p>
    <p>&#9757;&#127999; 深色</p>
    <p>&#9757;&#127997; 中等色</p>
    <p>&#9757;&#127995; 淺膚色</p>
</template>

效果:

更多參考:https://www.runoob.com/charsets/ref-emoji.html

2、 font-awesome 圖標(biāo)

安裝:npm i font-awesome

在項(xiàng)目主入口引入樣式文件(例:vue3項(xiàng)目main.ts):

import 'font-awesome/css/font-awesome.css';

使用示例:

<template>
	<i class="fa fa-smile-o"></i>
  	<i class="fa fa-phone"></i>
  	<i class="fa fa-commenting-o"></i>
</template>

更多參看:https://www.runoob.com/font-awesome/fontawesome-icons-webapp.html

3、v-emoji-picker

安裝: npm i v-emoji-picker

事件

@select - 選中表情時(shí)觸發(fā)

@changeCategory - 切換分類時(shí)觸發(fā)

屬性

  customEmojis: Array<IEmoji>, // 默認(rèn):[],自定義表情符號(hào)數(shù)組
  customCategories: Array<ICategory>, // 默認(rèn):[],自定義分類數(shù)組
  limitFrequently: number, // 默認(rèn):15,頻繁使用的表情限制數(shù)量
  emojisByRow: number, 		// 默認(rèn):5,每行的表情數(shù)
  continuousList: boolean, // 默認(rèn):false,是否連續(xù)滾動(dòng)列表
  emojiSize: number, 		// 默認(rèn):32,表情大小
  emojiWithBorder: boolean, // 默認(rèn):true,表情是否有邊框
  showSearch: boolean, 		// 默認(rèn):true,是否顯示搜索功能
  showCategories: boolean, // 默認(rèn):true,是否顯示分類選項(xiàng)
  dark: boolean, 			// 默認(rèn):false,暗黑模式
  initialCategory: string, // 默認(rèn):"Peoples",初始類別
  exceptCategories: Array<ICategory>, // 排除的類別數(shù)組,默認(rèn):[]
  exceptEmojis: Array<IEmoji>, // 排除的表情符號(hào)數(shù)組,默認(rèn):[]
  i18n: Object, 	// 國(guó)際化對(duì)象

具體示例:vue2 + element

// 第一步:在main.js引入emoji表情
import "font-awesome/css/font-awesome.css"; // 引入字體圖標(biāo)
import VEmojiPicker from "v-emoji-picker"; // 引入emoji圖標(biāo)
Vue.use(VEmojiPicker);

// 第二步:在組件中使用
<template>
  <div class="blog-container">
    <el-popover v-model="visibleEmoji" trigger="click">
      <VEmojiPicker @select="selectEmoji" />
      <i slot="reference" class="fa fa-smile-o"></i>
    </el-popover>
    <el-input v-model="inputValue" @blur="handleInputBlur" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      inputValue: "",
      visibleEmoji: false,
      blurPos: undefined
    };
  },
  methods: {
    handleInputBlur(e) {
      this.blurPos = e.srcElement.selectionStart;
    },
    selectEmoji(emoji) {
      if (this.inputValue === undefined) {
        this.inputValue = emoji.data;
      } else if (
        this.blurPos === undefined ||
        this.blurPos === this.inputValue.length
      ) {
        this.inputValue = `${this.inputValue}${emoji.data}`;
      } else {
        this.inputValue =
          this.inputValue.slice(0, this.blurPos) +
          emoji.data +
          this.inputValue.slice(this.blurPos);
      }
      this.visibleEmoji = false;
    }
  }
};
</script>

<style lang="less" scoped>
.blog-container {
  padding: 10px;
}
</style>

效果

v-emoji-picker官方npm庫(kù):https://www.npmjs.com/package/v-emoji-picker

4、vue3-emoji-picker

安裝: npm i vue3-emoji-picker

事件

@select - 選擇/點(diǎn)擊一個(gè)表情時(shí)觸發(fā)此事件,事件回調(diào)的第一個(gè)參數(shù)接收所選的表情。@update:text - 輸入文本發(fā)生變化時(shí)觸發(fā)此事件,事件回調(diào)的第一個(gè)參數(shù)接收改變后的文本

屬性

屬性類型默認(rèn)值描述
native布爾型false是否使用系統(tǒng)原生表情代替圖片。
hide-search布爾型true顯示或隱藏搜索輸入框。
hide-group-icons布爾型false顯示或隱藏分組圖標(biāo)。
hide-group-names布爾型false顯示或隱藏分組名稱。
disable-sticky-group-names布爾型false禁用分組名稱的固定位置顯示。
disable-skin-tones布爾型false禁用膚色選擇。
disabled-groups數(shù)組[]禁用特定的分組或類別。參見[可用分組]
group-names對(duì)象{}更改任意分組名稱。參見[默認(rèn)分組名稱]
static-texts對(duì)象對(duì)象參考[靜態(tài)文本選項(xiàng)]表。
pickerType字符串‘’選擇選擇器類型,可能的選項(xiàng):input、textarea(彈出輸入框或文本區(qū)域),''。
mode字符串'insert'選擇插入模式,可能的選項(xiàng):prepend、insert、append。
offset數(shù)字6設(shè)置表情彈窗的偏移量。
additional-groups對(duì)象{}添加自定義分組,鍵為從蛇形命名轉(zhuǎn)換過來的分組名稱。
group-order數(shù)組[]覆蓋分組的排序。
group-icons對(duì)象{}通過在鍵上傳遞 SVG 來覆蓋分組圖標(biāo)。
display-recent布爾型false顯示最近使用的表情。
theme字符串‘light’可選值:'light'、'dark'、'auto'。

靜態(tài)文本選項(xiàng)

屬性類型默認(rèn)值描述
placeholder字符串“Search emoji”更新搜索輸入框的占位符文本。
skinTone字符串“Skin tone”底部膚色按鈕的文本。

可用分組

[
  "smileys_people",
  "animals_nature",
  "food_drink",
  "activities",
  "travel_places",
  "objects",
  "symbols",
  "flags"
]

默認(rèn)分組名稱

{
  "smileys_people": "微笑與人物",
  "animals_nature": "動(dòng)物與自然",
  "food_drink": "食物與飲料",
  "activities": "活動(dòng)",
  "travel_places": "旅行與地點(diǎn)",
  "objects": "物體",
  "symbols": "符號(hào)",
  "flags": "旗幟"
}

具體示例:vue3 + antd

// 使用了TypeScript,需要在 .d.ts 文件中添加模塊聲明
declare module 'vue3-emoji-picker';

// 組件中使用
<template>
  <div class="warpper">
    <a-popover title=" " v-model:visible="showEmoji" trigger="click">
      <template #content>
        <Vue3EmojiPicker :native="true" @select="chooseEmoji" />
      </template>
      <i class="fa fa-smile-o" @click="showEmoji = !showEmoji"></i>
    </a-popover>
    <a-input
      v-model:value="inputValue"
      @blur="handleInputBlur"
      placeholder="請(qǐng)輸入"
    >
    </a-input>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { Input, Popover } from "ant-design-vue";
import Vue3EmojiPicker from "vue3-emoji-picker"; // 引入emoji表情組件
import "vue3-emoji-picker/css"; // 引入樣式

const showEmoji = ref<boolean>(false); // 是否顯示表情
const inputValue = ref<string | undefined>(undefined); // 輸入框的值
const blurPos = ref<number>(0); // 光標(biāo)位置

// 獲取光標(biāo)位置
function handleInputBlur(e) {
  blurPos.value = e.srcElement.selectionStart;
}

/* 選擇表情事件
  emoji示例:
    {
      n: ["face with tears of joy", "joy"],
      u: "1f602",
      r: "1f602",
      t: "neutral",
      i: "??",
    }
*/
function chooseEmoji(emoji) {
  if (inputValue.value === undefined) {
    inputValue.value = emoji.i;
  } else if (blurPos.value === undefined || blurPos.value === inputValue.value.length) {
    inputValue.value = `${inputValue.value}${emoji.i}`;
  } else {
    inputValue.value =
      inputValue.value.slice(0, blurPos.value) +
      emoji.i +
      inputValue.value.slice(blurPos.value);
  }
  showEmoji.value = false;
}
</script>

<style scoped>
.warpper {
  padding: 40px;
  border: 1px solid #ccc;
}

.emoji-wrap {
  text-align: left;
}
</style>

效果

vue3-emoji-picker更多說明,參考官方npm庫(kù):https://www.npmjs.com/package/vue3-emoji-picker?activeTab=explore

5、vue-emoji

安裝: npm i emoji-vue

事件與屬性

@input - 當(dāng)含有表情選擇器的textarea內(nèi)容改變時(shí)觸發(fā)的事件。

value - 用于設(shè)置textarea初始內(nèi)容的屬性。

width - 設(shè)置可見textarea的寬度(以像素為單位);默認(rèn)為’200px’。

height - 設(shè)置可見textarea的高度(以像素為單位);默認(rèn)為’50px’。

使用:vue2 + element 使用

<template>
  <div class="blog-container">
    <VueEmoji ref="emoji" :value="inputText" @input="onInput"></VueEmoji>
    <el-button type="primary" size="mini" @click="clearInput">清除</el-button>
  </div>
</template>

<script>
import VueEmoji from "emoji-vue";

export default {
  components: {
    VueEmoji
  },
  data() {
    return {
      inputValue: "",
      visibleEmoji: false,
      blurPos: undefined,
      inputText: ""
    };
  },
  methods: {
    onInput(emoji) {
      console.log(emoji);
    },
    clearInput() {
      this.$refs.emoji.clear();
    }
  }
};
</script>

<style lang="less" scoped>
.blog-container {
  padding: 10px;
}
</style>

效果

vue-emoji更多使用參考npm官方地址:https://www.npmjs.com/package/emoji-vue

以上就是一文教你如何在Vue項(xiàng)目中使用Emoji表情的詳細(xì)內(nèi)容,更多關(guān)于Vue使用Emoji表情的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論