// @ts-nocheck Component({ properties: { placeholder: { type: String, value: "请输入内容" }, value: { type: String, value: '' }, redirect: { //页面跳转的路径 type: String, value: '' } }, methods: { onInput(e: any) { this.setData({ value: e.detail.value }) //抛出一个事件,让父组件拿到输入值 this.triggerEvent('change', e.detail.value) }, onSearch() { const keyword = this.data.value.trim() if (keyword === '' || keyword == undefined) { wx.showToast({ title: '请输入商品名称!', icon: 'none' }) return } // 如果父组件绑定有search,则调父组件的方法 if (this.dataset.hasOwnProperty('search')) { this.triggerEvent('search', keyword) return } //否则执行默认跳转逻辑 if (this.data.redirect) { wx.navigateTo({ url: `${this.data.redirect}?keyword=${keyword}` }) } else { wx.showToast({ title: '未配置跳转页面', icon: 'none' }) } } } })