tag.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <script>
  2. export default {
  3. name: 'ElTag',
  4. props: {
  5. text: String,
  6. closable: Boolean,
  7. type: String,
  8. hit: Boolean,
  9. disableTransitions: Boolean,
  10. color: String,
  11. size: String,
  12. effect: {
  13. type: String,
  14. default: 'light',
  15. validator(val) {
  16. return ['dark', 'light', 'plain'].includes(val);
  17. }
  18. }
  19. },
  20. methods: {
  21. handleClose(event) {
  22. event.stopPropagation();
  23. this.$emit('close', event);
  24. },
  25. handleClick(event) {
  26. this.$emit('click', event);
  27. }
  28. },
  29. computed: {
  30. tagSize() {
  31. return this.size || (this.$ELEMENT || {}).size;
  32. }
  33. },
  34. render(h) {
  35. const { type, tagSize, hit, effect } = this;
  36. const classes = [
  37. 'el-tag',
  38. type ? `el-tag--${type}` : '',
  39. tagSize ? `el-tag--${tagSize}` : '',
  40. effect ? `el-tag--${effect}` : '',
  41. hit && 'is-hit'
  42. ];
  43. const tagEl = (
  44. <span
  45. class={ classes }
  46. style={{ backgroundColor: this.color }}
  47. on-click={ this.handleClick }>
  48. { this.$slots.default }
  49. {
  50. this.closable && <i class="el-tag__close el-icon-close" on-click={ this.handleClose }></i>
  51. }
  52. </span>
  53. );
  54. return this.disableTransitions ? tagEl : <transition name="el-zoom-in-center">{ tagEl }</transition>;
  55. }
  56. };
  57. </script>