微信小程序将获取的值放入到数组中去,结果数组中获取不到值,不懂求教

我获取到了value,但是把他push到history数组中,history里面没有值

  searchinto(e) {
    // console.log(e)
    const value = this.data.search.content;
    const history = this.data.history;
    console.log(value);
    history.push[value];
    console.log(history);
    this.setData({
      history
    })
  },

clipboard.png

阅读 4.1k
3 个回答

.push应该是小括号(),而不是中括号[]吧?

history.push(value);
this.setData({
      history:[...this.data.history, value]
    })

我看错了,已经知道了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题