如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
index.wxml
<form class='xf_box'> <view class="weui-search-bar"> <view class="weui-search-bar__form"> <view class="weui-search-bar__box"> <icon class="weui-icon-search_in-box" type="search" size="14"></icon> <input type="text" class="weui-search-bar__input" placeholder="搜索" value="{{inputVal}}" focus="{{inputShowed}}" bindinput="inputTyping" /> <view class="weui-icon-clear" wx:if="{{inputVal.length > 0}}" bindtap="clearInput"> <icon type="clear" size="14"></icon> </view> </view> <label class="weui-search-bar__label" hidden="{{inputShowed}}" bindtap="showInput"> <icon class="weui-icon-search" type="search" size="14"></icon> <view class="weui-search-bar__text">搜索</view> </label> </view> <view class="weui-search-bar__cancel-btn" hidden="{{!inputShowed}}" bindtap="hideInput">取消</view> </view> </form>
index.js
inputTyping: function (e) { var title = e.detail.value; console.log(e) // 加载新数据 this.setData({ inputVal: e.detail.value, }); //加载数据 var that = this wx.showLoading({ title: '' }) //获取该栏目下的列表 wx.request({ url: config.api_base_url + 'index/post_search_list' , header: { 'content-type': 'application/json' // 默认值 }, data: { keyword: title, }, success(res) { console.log(res.data.msg.length) if (res.data.msg.length == 0) { that.setData({ list_is: false }) }else{ that.setData({ list_is: true }) } that.setData({ list: res.data.msg, }) } }) setTimeout(function () { wx.hideLoading() }, 2000) },