button
<template>
<button
class="el-button"
@click="handleClick"
:disabled="buttonDisabled || loading"
:autofocus="autofocus"
:type="nativeType"
:class="[
type ? 'el-button--' + type : '',
buttonSize ? 'el-button--' + buttonSize : '',
{
'is-disabled': buttonDisabled,
'is-loading': loading,
'is-plain': plain,
'is-round': round,
'is-circle': circle
}
]"
>
<i class="el-icon-loading" v-if="loading"></i>
<i :class="icon" v-if="icon && !loading"></i>
<span v-if="$slots.default"><slot></slot></span>
</button>
</template>
<script>
export default {
name: 'ElButton',
inject: {
elForm: {
default: ''
},
elFormItem: {
default: ''
}
},
props: {
type: { // class, primary,success...... 设置颜色用
type: String,
default: 'default'
},
size: String,
icon: { // class, loading不存在且icon存在
type: String,
default: ''
},
nativeType: { // 原生 type 属性 button / submit / reset
type: String,
default: 'button'
},
loading: Boolean, // class loading为true,则使用element默认的loading
disabled: Boolean, // class
plain: Boolean, // class
autofocus: Boolean, // 自动聚焦(原生input属性, 页面加载时 input 元素应该自动获得焦点) 但是这里是button(好像autofocus没啥用)
round: Boolean, // class 圆角按钮
circle: Boolean // class 圆形按钮
},
computed: {
_elFormItemSize() {
return (this.elFormItem || {}).elFormItemSize; // button如果在el-form-item中,那么取其size
},
buttonSize() {
return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size; // ! this.$ELEMENT 是干什么用的?
},
buttonDisabled() {
return this.disabled || (this.elForm || {}).disabled; // 按钮本身不禁用,还要看el-form是否禁用按钮(好处:在一个表单中不需要对每个按钮都就行disable,子需要在el-form中设置即可,且form中的 el-button也可单独设置)
}
},
methods: {
handleClick(evt) {
this.$emit('click', evt);
}
}
};
</script>
button-group
<template>
<!-- 加了个div,设置了一些样式 -->
<div class="el-button-group">
<slot></slot>
</div>
</template>
<script>
export default {
name: 'ElButtonGroup'
};
</script>