index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <a class="m-link" :class="styleClass" :href="href" @click="handleClick">
  3. <i class="iconfont" :class="leftIcon" v-if="leftIcon"></i>
  4. <span :style="spanStyle">
  5. <slot />
  6. </span>
  7. <i class="iconfont" :class="rightIcon" v-if="rightIcon"></i>
  8. </a>
  9. </template>
  10. <script>
  11. export default {
  12. name: "mLink"
  13. };
  14. </script>
  15. <script setup>
  16. import { computed } from 'vue-demi';
  17. const props = defineProps({
  18. href: String,
  19. type: {
  20. type: String,
  21. default: 'default',
  22. validator(value) {
  23. return ['default','primary', 'success', 'info', 'warning', 'danger'].indexOf(value) > -1;
  24. }
  25. },
  26. disabled: {
  27. type: Boolean,
  28. default: false
  29. },
  30. underline: {
  31. type: Boolean,
  32. default: true
  33. },
  34. leftIcon: String,
  35. rightIcon: String
  36. })
  37. const styleClass = computed(() => {
  38. return {
  39. [`m-link--${props.type}`]: props.type,
  40. 'is-disabled': props.disabled,
  41. 'is-underline': props.underline && !props.disabled
  42. }
  43. })
  44. const spanStyle = computed(() => {
  45. return {
  46. 'margin-left': props.leftIcon ? '3px': '' ,
  47. 'margin-right': props.rightIcon ? '3px': ''
  48. }
  49. })
  50. const handleClick = (e) => {
  51. console.log(e);
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. @import '../../styles/components/link.scss';
  56. </style>