Tag: optimize code (#13069)

* Tag: optimize code

* update tag.vue
pull/13084/head
hetech 2018-10-17 16:36:45 +08:00 committed by GitHub
parent 868bbc71e7
commit 39fc1b29c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 17 deletions

View File

@ -1,20 +1,3 @@
<template>
<transition :name="disableTransitions ? '' : 'el-zoom-in-center'">
<span
class="el-tag"
:class="[
type ? 'el-tag--' + type : '',
tagSize && `el-tag--${tagSize}`,
{'is-hit': hit}
]"
:style="{backgroundColor: color}">
<slot></slot>
<i class="el-tag__close el-icon-close"
v-if="closable"
@click.stop="handleClose"></i>
</span>
</transition>
</template>
<script> <script>
export default { export default {
name: 'ElTag', name: 'ElTag',
@ -29,6 +12,7 @@
}, },
methods: { methods: {
handleClose(event) { handleClose(event) {
event.stopPropagation();
this.$emit('close', event); this.$emit('close', event);
} }
}, },
@ -36,6 +20,20 @@
tagSize() { tagSize() {
return this.size || (this.$ELEMENT || {}).size; return this.size || (this.$ELEMENT || {}).size;
} }
},
render(h) {
const classes = [ 'el-tag', this.type ? `el-tag--${this.type}` : '',
this.tagSize ? `el-tag--${this.tagSize}` : '',
{'is-hit': this.hit}
];
const tagEl = (<span class={classes} style={{backgroundColor: this.color}}>
{ this.$slots.default }
{
this.closable && <i class="el-tag__close el-icon-close" on-click={this.handleClose}></i>
}
</span>);
return this.disableTransitions ? tagEl : <transition name="el-zoom-in-center">{ tagEl }</transition>;
} }
}; };
</script> </script>