index.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // components/w-search/index.ts
  2. Component({
  3. options: {
  4. multipleSlots: true,
  5. styleIsolation: "shared",
  6. },
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. /**
  12. * 搜索框的值
  13. */
  14. value: {
  15. type: String,
  16. value: "",
  17. observer: '_value'
  18. },
  19. /**
  20. * 搜索框的占位符
  21. */
  22. placeholder: {
  23. type: String,
  24. value: "请输入搜索内容",
  25. },
  26. // 搜索框的占位符样式
  27. placeholderStyle: {
  28. type: String,
  29. value: "color: #BDBDBD;",
  30. },
  31. searchButtonText: {
  32. type: String,
  33. value: "搜索",
  34. },
  35. /**
  36. * 输入框的背景色 - 默认白色, [white gray]
  37. */
  38. backgroundClass: {
  39. type: String,
  40. value: 'white'
  41. }
  42. },
  43. /**
  44. * 组件的初始数据
  45. */
  46. data: {
  47. searchName: ""
  48. },
  49. /**
  50. * 组件的方法列表
  51. */
  52. methods: {
  53. onSearchChange(event: any) {
  54. this.setData({
  55. value: event.detail,
  56. });
  57. this.triggerEvent("change", event.detail);
  58. },
  59. onSearch() {
  60. // this.getSchools(this.data.searchName);
  61. this.triggerEvent("search", this.data.searchName)
  62. },
  63. _value() {
  64. this.setData({
  65. searchName: this.data.value
  66. })
  67. }
  68. },
  69. });