mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
72 lines
1.4 KiB
JavaScript
72 lines
1.4 KiB
JavaScript
const nativeBehaviors = require('./behaviors');
|
|
const classnames = require('../common/classnames');
|
|
|
|
const observer = function() {
|
|
this.setClasses();
|
|
};
|
|
|
|
Component({
|
|
externalClasses: ['custom-class', 'loading-class'],
|
|
|
|
behaviors: [nativeBehaviors],
|
|
|
|
properties: {
|
|
type: {
|
|
type: String,
|
|
value: 'default',
|
|
observer
|
|
},
|
|
size: {
|
|
type: String,
|
|
value: 'normal',
|
|
observer
|
|
},
|
|
plain: {
|
|
type: Boolean,
|
|
observer
|
|
},
|
|
disabled: {
|
|
type: Boolean,
|
|
observer
|
|
},
|
|
loading: {
|
|
type: Boolean,
|
|
observer
|
|
},
|
|
block: {
|
|
type: Boolean,
|
|
observer
|
|
},
|
|
square: {
|
|
type: Boolean,
|
|
observer
|
|
}
|
|
},
|
|
|
|
attached() {
|
|
this.setClasses();
|
|
},
|
|
|
|
methods: {
|
|
onClick() {
|
|
if (!this.data.disabled && !this.data.loading) {
|
|
this.triggerEvent('click');
|
|
}
|
|
},
|
|
|
|
setClasses() {
|
|
const { type, size, plain, disabled, loading, square, block } = this.data;
|
|
this.setData({
|
|
classes: classnames(`van-button--${type}`, `van-button--${size}`, {
|
|
'van-button--block': block,
|
|
'van-button--plain': plain,
|
|
'van-button--square': square,
|
|
'van-button--loading': loading,
|
|
'van-button--disabled': disabled,
|
|
'van-button--unclickable': disabled || loading
|
|
})
|
|
});
|
|
}
|
|
}
|
|
});
|