icon.vue 1012 B

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