收藏
回答

关于 this.setData的问题?

求助下,为什么中间那段 that.setData一直不进入执行呢?刚接触小程序,被它的执行方式搞晕了 。麻烦大佬路过时解答一下。提供个思路!

回答关注问题邀请回答
收藏

3 个回答

  • Cecilia
    Cecilia
    2022-04-20

    因为两个success的返回值都写了res吧,把其中一个换个名字试试嘞

    2022-04-20
    有用 2
    回复
  • 睡前原谅一切
    睡前原谅一切
    2022-04-18
    upload(filePath) {
      wx.cloud.uploadFile({
        cloudPath: `photo/${Date.now()}.png`,
        filePath,
        success: resp => {
           let { imageList } = this.data
           wx.cloud.getTempFileURL({
              fileList: [resp.fileID],
              success: res => {
                 console.log(1, res)
                 this.setData({
                     showUploadImageIcon: true,
                     showUploadImage: false,
                     imageList: imageList.concat([res.fileList[0].tempFileURL)
                 }, () => {
                    console.log(2, this.data.imageList)
                 })
              },
              fail: err => {
                  wx.showToast({
                      title: '请稍后重试',
                      icon: 'error'
                  })
              }
           })
        }
      })
    }
    
    


    2022-04-18
    有用 1
    回复 6
    • Z
      Z
      发表于移动端
      2022-04-18
      您好,我按照您的建议更改了之后还是不行,程序始终没有执行that.setData里的语句,以至于showUploadImageIcon与showUploadImage也没有被修改。想问下还有可能是因为什么地方出问题了?
      2022-04-18
      回复
    • 睡前原谅一切
      睡前原谅一切
      2022-04-18回复Z
      再给你改了下
      2022-04-18
      回复
    • Z
      Z
      2022-04-18回复睡前原谅一切
      已经成功了!请问您这是因为什么呢?感谢您的解答,祝您生活愉快
      2022-04-18
      回复
    • 睡前原谅一切
      睡前原谅一切
      2022-04-18回复Z
      没看到报错原因 不清楚。。手写了下。。
      2022-04-18
      回复
    • Z
      Z
      发表于移动端
      2022-04-18回复睡前原谅一切
      控制台没有报错的
      2022-04-18
      回复
    查看更多(1)
  • 那一抹笑😃 穿透阳光
    那一抹笑😃 穿透阳光
    2022-04-18

    图片push代码有问题,imageList哪里来的,你完全没有定义这个参数,怎么能用,你应该先写

    let imageList = that.data.imgaeList; 才能使用imageList.push


    2022-04-18
    有用
    回复 1
    • Z
      Z
      发表于移动端
      2022-04-18
      嗯嗯,我照您说的方法试了,也是不行。而且实际上就连showUploadImageIcon和showUploadImage也没有被赋值
      2022-04-18
      回复
登录 后发表内容