微信小程序 数据绑定有时候不显示;有时候又正常 ?
发布于 5 年前 作者 wqiao 373 次浏览 来自 问答

在iOS版本的搜索 点击搜索词 会及时显示

在安卓机器上不会显示

同样问题 发现 在 亚马逊海淘购 这个小程序的 搜索框 也会出现 有时候显示 有时候不显示问题。

代码参考

<view class="page"  >
  <view class="page__hd">
    <view class="page__title">SearchBar</view>
    <view class="page__desc">搜索栏</view>
  </view>
  <view class="page__bd">
    <view class="weui-search-bar {{inputShowed ? 'weui-search-bar_focusing' : ''}}" id="searchBar">
      <form class="weui-search-bar__form">
        <view class="weui-search-bar__box">
          <i class="weui-icon-search"></i>
                    <input type="text" class="weui-search-bar__input" placeholder="搜索" value="{{inputVal}}" focus="{{inputShowed}}" bindinput="inputTyping" />
                    <span class="weui-icon-clear" wx:if="{{inputVal.length > 0}}" bindtap="clearInput"></span>
        </view>
        <label class="weui-search-bar__label" bindtap="showInput">
          <i class="weui-icon-search"></i>
                    <span class="weui-search-bar__text">搜索</span>
        </label>
      </form>
            <view class="weui-search-bar__cancel-btn" bindtap="hideInput">取消</view>
    </view>
    <view class="weui-cells searchbar-result" wx:if="{{inputVal.length > 0}}">
      <view class="weui-cell weui-cell_active weui-cell_access">
        <view class="weui-cell__bd weui-cell_primary">
          <view>{{inputVal}}</view>
        </view>
      </view>
      <view class="weui-cell weui-cell_active weui-cell_access">
        <view class="weui-cell__bd weui-cell_primary">
          <view data-val="搜索你好" bindtap="search">搜索你好</view>
        </view>
      </view>
     
    </view>
  </view>
</view>

Page({
     
    data: {
        inputShowedfalse,
        inputVal""
    },
    showInputfunction () {
        this.setData({
            inputShowedtrue
        });
    },
    hideInputfunction () {
        this.setData({
            inputVal"",
            inputShowedfalse
        });
    },
    clearInputfunction () {
        this.setData({
            inputVal""
        });
    },
    inputTypingfunction (e{
        this.setData({
            inputVal: e.detail.value
        });
    },
    search:function(e){
        let val=e.currentTarget.dataset.val
        this.setData({
            inputVal:val
        });
    }

});

回到顶部