zoukankan      html  css  js  c++  java
  • 微信小程序wx.uploadFile的两个坑

    --

    setImage:function(e){
        var _this = this  //坑1
        wx.chooseImage({
          count: 1, 
          sizeType: ['original', 'compressed'], 
          sourceType: ['album', 'camera'], 
          success: function (res) {
            var tempFilePaths = res.tempFilePaths
            console.log(tempFilePaths)
            wx.uploadFile({
              url: app.globalData.myhost+'customer-header?access_token='+app.globalData.itoken,
              filePath: tempFilePaths[0],
              name: 'uploadFile',
              formData: {
                'userId': app.globalData.iuserId
              },
              success: function (res) {var data = JSON.parse(res.data)  //坑2:与wx.request不同,wx.uploadFile返回的是[字符串],需要自己转为JSON格式
                console.log('上传成功')
                _this.setData({    //坑1:wx.uploadFile本身有一个this,所以要通过外部var _this = this 把this带进来
                  headerImageUrl: data.headerImageUrl
                })
                console.log('刷新成功')
              }
            })
          }
        })
      },

    --

  • 相关阅读:
    nodejs websocket
    [Java] 数组-01 入门
    [Java] 第一,二章 配置, 基础
    [Java] 第四章 异常机制
    [Java] 第三章 面向对象总结
    [Java] 接口-02
    [Java] 接口-01
    [Java] final 关键字
    [Java] 抽象类
    [Java] 多态-01
  • 原文地址:https://www.cnblogs.com/Ph-one/p/11864604.html
Copyright © 2011-2022 走看看