icon.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <i
  3. :class="['nut-icon', 'nut-icon-' + type]"
  4. v-html="icon"
  5. :style="{ height: size, width: size, color: color }"
  6. ></i>
  7. </template>
  8. <script>
  9. const types = [
  10. 'top',
  11. 'action',
  12. 'cross',
  13. 'down',
  14. 'right',
  15. 'more',
  16. 'plus',
  17. 'search',
  18. 'trolley',
  19. 'tick',
  20. 'minus',
  21. 'circle-cross',
  22. 'avatar',
  23. 'nav',
  24. 'star',
  25. 'set',
  26. 'notice'
  27. ];
  28. export default {
  29. name: 'nut-icon',
  30. props: {
  31. type: {
  32. type: String,
  33. default: ''
  34. },
  35. size: {
  36. type: String,
  37. default: ''
  38. },
  39. color: {
  40. type: String,
  41. default: '#2e2d2d'
  42. },
  43. url: {
  44. type: String,
  45. default: ''
  46. }
  47. },
  48. data() {
  49. return {
  50. icon: null
  51. };
  52. },
  53. watch: {
  54. url(val) {
  55. this.icon = val;
  56. }
  57. },
  58. created() {
  59. if (this.url) {
  60. this.icon = this.url;
  61. this.type = 'self';
  62. } else {
  63. if (types.indexOf(this.type) === -1) {
  64. console.error('nut-icon组件type值(' + this.type + ')有误,无此icon!');
  65. } else {
  66. this.icon = require('../../assets/svg/' + this.type + '.svg');
  67. }
  68. }
  69. }
  70. };
  71. </script>