- Cannot read property 'onProgressUpdate' ?求大神帮忙
// 阅读图书 readBook:function(e){ var that = this // 获取当前点击图书的ID let id = e.currentTarget.dataset.id // 获取当前点击图书的Url let fileUrl = e.currentTarget.dataset.file // 查看本地缓存 let path =wx.getStorageSync(id) // 未曾下载过 if(path ==''){ // 切换到下载时的蒙层 that.setData({ isDownloading:true }) // 先下载图书 const downloadTask = wx.downloadFile({ url:fileUrl, success:function(res){ // 关闭下载时的蒙层 that.setData({ isDownloading:false }) // 下载成功 if (res.statusCode == 200){ // 获取地址 path = res.tempFilePath // 保存并打开图书 that.saveBook(id,path) } // 连上服务器,下载失败 else{ that.showTips('暂时无法下载') } }, //请求失败 fail:function(e){ // 关闭下载时的蒙层 that.setData({ isDownloading:false }) that.showTips('无法连接到服务器!') } }) // 监听当前文件下载的下载速度 downloadTask.onProgressUpdate((res) =>{ let progress = res.progress that.setData({ percentNum: progress }) }) } else{ // 打开图书 that.openBook(path) } }, 当我点击图书下载前,无错误,但当我点击时,只会提示弹出‘无法连接到服务器’这个消息框,但是无法下载,并出错以下错误 thirdScriptError Cannot read property 'onProgressUpdate' of undefined; [Component] Event Handler Error @ pages/index/index#bound readBook TypeError: Cannot read property 'onProgressUpdate' of undefined at me.readBook (http://127.0.0.1:52924/appservice/pages/index/index.js:141:18) at Object.r.safeCallback (http://127.0.0.1:52924/appservice/__dev__/WAService.js:2:1434440) at http://127.0.0.1:52924/appservice/__dev__/WAService.js:2:1552253 at s (http://127.0.0.1:52924/appservice/__dev__/WAService.js:2:1561021) at http://127.0.0.1:52924/appservice/__dev__/WAService.js:2:1552178 at r (http://127.0.0.1:52924/appservice/__dev__/WAService.js:2:1505702) 当我点击图书时,只提示‘无法连接到服务器’这个选项,但是无法下载, ’‘
2020-03-13 - function is a reserved word ?如何解决,求高手帮忙
function getRandomColor(){ let rgb = [] for(let i=0;i<3;i++){ let color = Math.floor(Math.random()*256).toString(16) color = color.length==1?'0'+color:color rgb.push(color) } return '#'+rgb.join('') } //以下为错误提示 VM4193:1 file: pages/index/index.js unknown: function is a reserved word (118:2) 116 | }, 117 | > 118 | function getRandomColor(){ | ^ 119 | let rgb = [] 120 | for(let i = 0;i<3; i++){ 121 | let color = Math.floor(Math.random() * 256).toString(16) 改成以下方式可以表达,但是反馈的颜色一直是白色,无法随机 //生成随机颜色 getRandomColor: function (){ let rgb = [ ] for ( let i = 0; i< 3; ++i ) { let color = Math.floor(Math.random() * 256).toString(16) color = color.length == 1 ? '0' + color:color rgb.push(color) } return '#' + rgb.join(' ') }
2020-03-12 - that.setDate is not a function错误如何解决呢?求大神指导
getWeather: function(){ var that = this; wx.request({ url: 'https://free-api.heweather.com/s6/weather/now', data:{ location:that.data.region[1], key:'07e21eda4e604f8dbce0d1' }, success: function(res){ that.setDate({ now:res.data.HeWeather6[0].now }); } })
2020-03-12