index.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="cl-avatar" :class="[size, shape]" :style="[style2]">
  3. <el-image :src="src" alt="">
  4. <div slot="error" class="image-slot">
  5. <i class="el-icon-picture-outline"></i>
  6. </div>
  7. </el-image>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. name: "cl-avatar",
  13. props: {
  14. src: String,
  15. size: {
  16. type: String,
  17. default: "large"
  18. },
  19. shape: {
  20. type: String,
  21. default: "circle"
  22. }
  23. },
  24. data() {
  25. return {
  26. style2: {}
  27. };
  28. },
  29. mounted() {
  30. if (typeof this.size == "number") {
  31. this.style2 = {
  32. height: this.size + "px",
  33. width: this.size + "px"
  34. };
  35. }
  36. }
  37. };
  38. </script>
  39. <style lang="scss" scoped>
  40. .cl-avatar {
  41. overflow: hidden;
  42. background-color: #f7f7f7;
  43. &.large {
  44. height: 50px;
  45. width: 50px;
  46. }
  47. &.medium {
  48. height: 40px;
  49. width: 40px;
  50. }
  51. &.small {
  52. height: 30px;
  53. width: 30px;
  54. }
  55. &.circle {
  56. border-radius: 100%;
  57. }
  58. &.square {
  59. border-radius: 10%;
  60. }
  61. img {
  62. height: 100%;
  63. width: 100%;
  64. }
  65. .el-image {
  66. height: 100%;
  67. width: 100%;
  68. /deep/.image-slot {
  69. display: flex;
  70. justify-content: center;
  71. align-items: center;
  72. height: 100%;
  73. width: 100%;
  74. i {
  75. font-size: 20px;
  76. }
  77. }
  78. }
  79. .el-icon-picture-outline {
  80. color: #ccc;
  81. }
  82. }
  83. </style>