search.js 780 B

1234567891011121314151617181920212223242526272829303132
  1. let count = null;
  2. Component({
  3. properties: {
  4. inputSharch: {
  5. type: Function
  6. }
  7. },
  8. data: {
  9. isClear: false
  10. },
  11. options: {
  12. addGlobalClass: true,
  13. },
  14. methods: {
  15. textChange(e) {
  16. clearTimeout(count);
  17. if (this.data.isClear) {
  18. this.triggerEvent("inputSharch");
  19. this.setData({
  20. isClear: false
  21. })
  22. return;
  23. }
  24. e.type == "change" ? count = setTimeout(() => this.triggerEvent("inputSharch", e.detail.trim()), 1000) : this.triggerEvent("inputSharch", e.detail.trim());
  25. },
  26. onClear() {
  27. this.setData({
  28. isClear: true
  29. })
  30. }
  31. }
  32. })