小程序官方提供的表情库可以通过以下步骤在小程序中引入并使用:
- 在小程序工具中打开项目,进入app.json文件,在"pages"字段中添加"wxs"页面路径,例如:"pages/wxs/wxs"。
- 在项目中新建"wxs"文件夹,存放自定义表情相关的JS文件和图片。
- 在"wxs"页面中使用官方提供的表情组件,例如:
<emoji-group bind:select="onSelect"> </emoji-group>
- 在"wxs"页面的JS文件中实现"onSelect"函数,用来获取选择的表情信息,例如:
onSelect: function(e) {
console.log(e.detail);
}
- 在"wxs"页面的JS文件中引入官方提供的表情组件库,例如:
var emoji = require('../../libs/emoji.js');
Page({
data: {
list: emoji.emoji_data
},
// ...
})
- 在"wxs"页面的WXML文件中使用官方表情组件库提供的表情标签,例如:
<view wx:for="{{list}}" wx:key="{{index}}">
<emoji type="{{item.type}}" size="{{40}}" @click="onSelect" binderror="error">
<image src="{{item.url}}" />
</emoji>
</view>
- 这样就可以在小程序中使用官方提供的表情库了。