鍍金池/ 問(wèn)答/HTML/ 微信小程序選擇圖片上傳的問(wèn)題

微信小程序選擇圖片上傳的問(wèn)題

請(qǐng)問(wèn)微信小程序,將以下代碼綁定到view組件上,點(diǎn)擊上傳圖片后為什么報(bào)錯(cuò)

upLoadImage: function(event) {
       var id = event.currentTarget.id
       var that = this
       wx.chooseImage({
           count: 1, 
           sizeType: ['original', 'compressed'], 
           sourceType: ['album', 'camera'], 
           success: function(res) {
               var tempFilePaths = res.tempFilePaths
               wx.uploadFile({
                   url: '/wx/upload',
                   filePath: tempFilePaths[0],
                   name: 'image_file',
                   success: function (res) {

                   }
               })
           },
       })
    }

錯(cuò)誤代碼是:

uploadFile:fail Cannot read property '0' of null

感覺(jué)是tempFilePaths參數(shù)沒(méi)有傳入uploadFile函數(shù)中,但是函數(shù)中不是應(yīng)該能讀取外層函數(shù)的變量嗎?

回答
編輯回答
柒槿年

我也遇到過(guò)這問(wèn)題 把url 寫(xiě)完整了就可以了
例如: /wx/upload 改成 http://wx/upload 或者 https://wx/upload

2018年1月24日 23:59
編輯回答
掛念你

真機(jī)沒(méi)問(wèn)題,我也遇到過(guò),然后莫名其妙就好了

2017年12月17日 10:18
編輯回答
朽鹿

請(qǐng)問(wèn)解決了嗎 ? 如何解決的?

2017年8月28日 07:54