index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <span class="m-tag" :class="styleClass" :style="colorStyle" @click="handleClick">
  3. <slot />
  4. <i class="iconfont icon-close" v-if="closable" @click="handleClose"></i>
  5. </span>
  6. </template>
  7. <script>
  8. import { computed } from 'vue-demi';
  9. export default {
  10. name: "mTag"
  11. };
  12. </script>
  13. <script setup>
  14. const emit = defineEmits(['click','close'])
  15. const props = defineProps({
  16. type: String,
  17. closable: {
  18. type: Boolean,
  19. default: false
  20. },
  21. bgColor: String,
  22. color: String,
  23. size: String,
  24. effect: {
  25. type: String,
  26. default: 'light',
  27. validator(val) {
  28. return ['dark', 'light', 'plain'].indexOf(val) !== -1;
  29. }
  30. }
  31. })
  32. const styleClass = computed(() => {
  33. return {
  34. [`m-tag--${props.type}`]: props.type,
  35. [`m-tag--${props.size}`]: props.size,
  36. [`m-tag--${props.effect}`]: props.effect
  37. }
  38. })
  39. const colorStyle = computed(() => {
  40. return {
  41. backgroundColor: props.bgColor,
  42. color: props.color
  43. }
  44. })
  45. const handleClick = (event) => {
  46. emit('click',event)
  47. }
  48. const handleClose = (event) => {
  49. event.stopPropagation();
  50. emit('close',event)
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. @import '../../styles/components/tag.scss';
  55. </style>