index.js 793 B

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