vi-icon
Version:
50 lines (49 loc) • 1.14 kB
JavaScript
const app = getApp()
Component({
properties: {
iconName: String,
fontFamily: {
type: String,
value: 'custom-font'
},
fontSource: String,
},
externalClasses: ['icon-style'],
lifetimes: {
attached() {
this.configHandle(app._$ViIcon);
}
},
data: {
hasGlobalConfig: false
},
methods: {
triggerToClickIcon() {
this.triggerEvent("clickIcon")
},
loadFontFace(log) {
const _this = this
wx.loadFontFace({
family: _this.data.fontFamily,
source: _this.data.fontSource,
});
},
configHandle({fontSource, fontFamily} = {fontSource: '', fontFamily: 'custom-font'}) {
if (this.data.fontSource) {
this.setData({
hasConfigFontSource: true
})
this.loadFontFace('dataFont')
} else {
if (!fontSource) return false;
if(!fontSource.includes('https')) throw Error('资源文件地址应为https开头');
this.setData({
fontSource,
fontFamily,
hasConfigFontSource: true
})
this.loadFontFace('configFont');
}
}
}
})