input组件获取键盘数值,引发的setData的问题?
发布于 4 年前 作者 jing55 2128 次浏览 来自 官方Issues

两种对输入框中数值消失的做法

wxml

 <input bindblur="_inputBlur" type="text" value="{{inputValue}}" />

然后我设置了一个按钮,点击就能把输入框清空

 _btnsend() {
    if (!this.data.inputValue) {
      console.log("内容为空");
    } else {
      console.log("内容不为空");
      this.setData({inputValue:""})      //此处与下面不同
    }

以上方式是可以实现的

但是我如果这样

 _btnsend() {
    if (!this.data.inputValue) {
      console.log("内容为空");
    } else {
      console.log("内容不为空");
      this.setData(this.data.inputValue="")    // inputValue是input组件内的默认值
    }

那么无论我怎么点击这个按钮输入框都不能被清空

请问为什么呢?第二种为什么不会刷新页面。

2 回复

有这种写法的吗,我怎么没见过,直接this.data.inputValue是改值,并不会触发渲染

第二种setData无法渲染页面吗

回到顶部