- 首先打开iconfont官网https://www.iconfont.cn/,登录
- 把需要的icon加入在自己项目中,在自己的iconfont项目中选择Unicode,点击查看在线链接,如上图所示
- 在template中使用iconfont,直接复制icon font代码即可,注意必须要设置font-family
<text class="used-title-right iconfont"></text>
<style scoped>
.iconfont {
font-family: iconfont5;//这个必须要!!!
}
</style>
- 官方推荐的做法是在beforecreated这个生命周期里加载iconfont
beforeCreate() {
var domModule = weex.requireModule('dom');
domModule.addRule('fontFace', {
'fontFamily': "iconfont5",
'src': "url('http://at.alicdn.com/t/font_1155166_lnwa38sb4g.ttf')"
});
},
搞定拉,快去查看效果