index.js 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { VantComponent } from '../common/component';
  2. import { RED } from '../common/color';
  3. import { safeArea } from '../mixins/safe-area';
  4. VantComponent({
  5. mixins: [safeArea()],
  6. props: {
  7. text: String,
  8. color: {
  9. type: String,
  10. value: '#fff'
  11. },
  12. backgroundColor: {
  13. type: String,
  14. value: RED
  15. },
  16. duration: {
  17. type: Number,
  18. value: 3000
  19. },
  20. zIndex: {
  21. type: Number,
  22. value: 110
  23. }
  24. },
  25. methods: {
  26. show() {
  27. const { duration } = this.data;
  28. clearTimeout(this.timer);
  29. this.set({
  30. show: true
  31. });
  32. if (duration > 0 && duration !== Infinity) {
  33. this.timer = setTimeout(() => {
  34. this.hide();
  35. }, duration);
  36. }
  37. },
  38. hide() {
  39. clearTimeout(this.timer);
  40. this.set({
  41. show: false
  42. });
  43. }
  44. }
  45. });