index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!--
  2. * @Author: liuye
  3. * @LastEditors: fhj
  4. * @Description:
  5. -->
  6. <template>
  7. <div v-if="isExternal" :style="styleExternalIcon" class="svg-external-icon svg-icon" v-on="$listeners" />
  8. <svg v-else :class="svgClass" aria-hidden="true" v-on="$listeners">
  9. <use :href="iconName" />
  10. </svg>
  11. </template>
  12. <script>
  13. import { isExternal } from '../../utils/validate';
  14. export default {
  15. name: 'FIcon',
  16. props: {
  17. iconClass: {
  18. type: String,
  19. required: true
  20. },
  21. className: {
  22. type: String,
  23. default: ''
  24. }
  25. },
  26. computed: {
  27. isExternal() {
  28. return isExternal(this.iconClass);
  29. },
  30. iconName() {
  31. return `#icon-${this.iconClass}`;
  32. },
  33. svgClass() {
  34. if (this.className) {
  35. return 'svg-icon ' + this.className;
  36. } else {
  37. return 'svg-icon';
  38. }
  39. },
  40. styleExternalIcon() {
  41. return {
  42. mask: `url(${this.iconClass}) no-repeat 50% 50%`,
  43. '-webkit-mask': `url(${this.iconClass}) no-repeat 50% 50%`
  44. };
  45. }
  46. }
  47. };
  48. </script>
  49. <style scoped>
  50. .svg-icon {
  51. width: 1em;
  52. height: 1em;
  53. vertical-align: -0.15em;
  54. fill: currentColor;
  55. overflow: hidden;
  56. }
  57. .svg-external-icon {
  58. background-color: currentColor;
  59. mask-size: cover!important;
  60. display: inline-block;
  61. }
  62. </style>