element/packages/button/src/button.vue

72 lines
1.5 KiB
Vue
Raw Normal View History

<template>
<button
class="el-button"
2016-10-28 09:29:18 +00:00
@click="handleClick"
2017-10-04 12:44:56 +00:00
:disabled="disabled"
:autofocus="autofocus"
:type="nativeType"
:class="[
2016-10-25 03:33:39 +00:00
type ? 'el-button--' + type : '',
2017-10-12 09:50:06 +00:00
buttonSize ? 'el-button--' + buttonSize : '',
{
'is-disabled': disabled,
'is-loading': loading,
'is-plain': plain,
'is-round': round
}
]"
>
<i class="el-icon-loading" v-if="loading" @click="handleInnerClick"></i>
<i :class="icon" v-if="icon && !loading" @click="handleInnerClick"></i>
<span v-if="$slots.default" @click="handleInnerClick"><slot></slot></span>
</button>
</template>
<script>
export default {
name: 'ElButton',
2017-10-12 09:50:06 +00:00
inject: ['elFormItem'],
props: {
type: {
type: String,
default: 'default'
},
size: String,
icon: {
type: String,
default: ''
},
nativeType: {
type: String,
default: 'button'
},
loading: Boolean,
disabled: Boolean,
plain: Boolean,
autofocus: Boolean,
round: Boolean
2016-10-28 09:29:18 +00:00
},
2017-10-12 09:50:06 +00:00
computed: {
_elFormItemSize() {
return (this.elFormItem || {}).elFormItemSize;
},
buttonSize() {
return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
}
},
2016-10-28 09:29:18 +00:00
methods: {
handleClick(evt) {
this.$emit('click', evt);
},
handleInnerClick(evt) {
if (this.disabled) {
evt.stopPropagation();
}
2016-10-28 09:29:18 +00:00
}
}
};
</script>