提示Uncaught (in promise)

来源:13-12 短评实现六:支持input输入短评

weixin_慕盖茨1194024

2019-06-21

图片描述
book-detail.js:91 Uncaught (in promise) TypeError: _this2.data.comments.unshift is not a function
at book-detail.js:91
at
老师请问如何解决,一样的代码:
onPost(event) {
const comment = event.detail.text || event.detail.value

if(!comment){
  return
}

if (comment.length > 12) {
  wx.showToast({
    title: '短评最多12个字',
    icon: 'none'
  })
  return
}

bookModel.postComment(this.data.book.id, comment)
  .then(res => {
    wx.showToast({
      title: '追加评论成功',
      icon: 'none'
    })

    this.data.comments.unshift({
      content: comment,
      nums: 1
    })

    this.setData({
      comments: this.data.comments,
      posting: false
    })
  })
写回答

2回答

宛在水中沚a

2019-06-21

截一下你的data初始化的数据   应该是comments 没有初始化复制吧   不能识别为数组  或者看一下报错的那一行和上下文

1
1
慕桂英1672925
我也遇到了一样的问题,已经解决了
2021-10-15
共1条回复

7七月

2019-06-22

肯定代码不一样,不然怎么会报错呢。book-detail.js:91 Uncaught (in promise) TypeError: _this2.data.comments.unshift is not a function
at book-detail.js:91

这个提示很明显了呀。

0
0

纯正商业级微信小程序应用实战,全方位小程序特性讲解

真实数据的高质量小程序项目,学会直接工作

4782 学习 · 2125 问题

查看课程