avatar.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <script>
  2. export default {
  3. name: "LemonAvatar",
  4. props: {
  5. src: String,
  6. icon: {
  7. type: String,
  8. default: "lemon-icon-people"
  9. },
  10. size: {
  11. type: Number,
  12. default: 32
  13. }
  14. },
  15. data() {
  16. return {
  17. imageFinishLoad: true
  18. };
  19. },
  20. render() {
  21. return (
  22. <span
  23. style={this.style}
  24. class="lemon-avatar"
  25. on-click={e => this.$emit("click", e)}
  26. >
  27. {this.imageFinishLoad && <i class={this.icon} />}
  28. <img src={this.src} onLoad={this._handleLoad} />
  29. </span>
  30. );
  31. },
  32. computed: {
  33. style() {
  34. const size = `${this.size}px`;
  35. return {
  36. width: size,
  37. height: size,
  38. lineHeight: size,
  39. fontSize: `${this.size / 2}px`
  40. };
  41. }
  42. },
  43. methods: {
  44. _handleLoad() {
  45. this.imageFinishLoad = false;
  46. }
  47. }
  48. };
  49. </script>
  50. <style lang="stylus">
  51. @import '~styles/utils/index'
  52. +b(lemon-avatar)
  53. font-variant tabular-nums
  54. line-height 1.5
  55. box-sizing border-box
  56. margin 0
  57. padding 0
  58. list-style none
  59. display inline-block
  60. text-align center
  61. background #ccc
  62. color rgba(255,255,255,0.7)
  63. white-space nowrap
  64. position relative
  65. overflow hidden
  66. vertical-align middle
  67. border-radius 4px
  68. img
  69. width 100%
  70. height 100%
  71. display block
  72. </style>