tt-mp
Version:
一套组件化、可复用、易扩展的头条小程序 UI 组件库
48 lines (45 loc) • 808 B
JavaScript
Component({
externalClasses: ['wux-class'],
properties: {
type: {
type: String,
value: '',
},
size: {
type: [String, Number],
value: 32,
observer: 'updated',
},
color: {
type: String,
value: '',
},
hidden: {
type: Boolean,
value: false,
},
},
data: {
fontSize: '',
},
methods: {
updated(size = this.data.size) {
let fontSize = size
if (typeof size === 'number') {
fontSize = `${size}px`
} else if (typeof size === 'string') {
if (!isNaN(Number(size))) {
fontSize = `${size}px`
}
}
if (this.data.fontSize !== fontSize) {
this.setData({
fontSize,
})
}
},
},
attached() {
this.updated()
},
})