index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { VantComponent } from '../common/component';
  2. import { button } from '../mixins/button';
  3. VantComponent({
  4. mixins: [button],
  5. classes: ['custom-class', 'loading-class', 'error-class', 'image-class'],
  6. props: {
  7. src: {
  8. type: String,
  9. observer() {
  10. this.setData({
  11. error: false,
  12. loading: true,
  13. });
  14. },
  15. },
  16. round: Boolean,
  17. width: null,
  18. height: null,
  19. radius: null,
  20. lazyLoad: Boolean,
  21. useErrorSlot: Boolean,
  22. useLoadingSlot: Boolean,
  23. showMenuByLongpress: Boolean,
  24. fit: {
  25. type: String,
  26. value: 'fill',
  27. },
  28. webp: {
  29. type: Boolean,
  30. value: false,
  31. },
  32. showError: {
  33. type: Boolean,
  34. value: true,
  35. },
  36. showLoading: {
  37. type: Boolean,
  38. value: true,
  39. },
  40. },
  41. data: {
  42. error: false,
  43. loading: true,
  44. viewStyle: '',
  45. },
  46. methods: {
  47. onLoad(event) {
  48. this.setData({
  49. loading: false,
  50. });
  51. this.$emit('load', event.detail);
  52. },
  53. onError(event) {
  54. this.setData({
  55. loading: false,
  56. error: true,
  57. });
  58. this.$emit('error', event.detail);
  59. },
  60. onClick(event) {
  61. this.$emit('click', event.detail);
  62. },
  63. },
  64. });