SearchBox.js 925 Bytes
// components/SearchBox/SearchBox.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    placeholder: {
      type: String,
      value: '请输入搜索内容'
    },
    value: {
      type: null,
      value: ''
    },
    searchType: {
      type: Number,
      value: 1
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
  },

  /**
   * 组件的方法列表
   */
  methods: {
    input(e) {
      let {
        value
      } = e.detail
      this.setData({
       value
      })
    },
    blur(e){
      let {value} = this.data
      this.setData({
        value
      })
    },
    clear() {
      this.setData({
        value: ''
      })
    },
    confirm(e) {
      let {
        value
      } = e.detail
      this.triggerEvent('search', value)
    },
    search(e) {
      let {
        value
      } = e.currentTarget.dataset
      this.triggerEvent('search', value)
    }
  }
})