46 lines
908 B
JavaScript
Raw Normal View History

2025-06-06 15:17:30 +08:00
Component({
options: {
// 允许外部样式影响组件
styleIsolation: 'apply-shared'
},
properties: {
name: {
type: String,
value: '',
required: true
},
size: {
type: String,
value: ''
},
index: {
type: Number,
value: 0
},
extClass: {
type: String,
value: ''
}
},
observers: {
// 自动补全单位数字默认加rpx
'size': function(val) {
if (!val) return
this.setData({
formattedSize: /\d$/.test(val) ? `${val}rpx` : val
})
}
},
data: {
formattedSize: ''
},
methods: {
handleClick() {
this.triggerEvent('click', { index: this.properties.index })
}
}
})