searchbar.js 783 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import CustomPage from '../../../base/CustomPage'
  2. CustomPage({
  3. onShareAppMessage() {
  4. return {
  5. title: 'searchbar',
  6. path: 'page/weui/example/searchbar/searchbar'
  7. }
  8. },
  9. data: {
  10. inputShowed: false,
  11. inputVal: '',
  12. i: 0
  13. },
  14. onLoad() {
  15. this.setData({
  16. search: this.search.bind(this)
  17. })
  18. },
  19. search() {
  20. return new Promise((resolve) => {
  21. if (this.data.i % 2 === 0) {
  22. setTimeout(() => {
  23. resolve([{text: '搜索结果', value: 1}, {text: '搜索结果2', value: 2}])
  24. }, 200)
  25. } else {
  26. setTimeout(() => {
  27. resolve([])
  28. }, 200)
  29. }
  30. this.setData({
  31. i: this.data.i + 1
  32. })
  33. })
  34. },
  35. selectResult(e) {
  36. console.log('select result', e.detail)
  37. },
  38. })