这里通过干活集中营的API接口真实请求下数据。如果提示URL 域名不合法,请在 mp 后台配置后重试修改asdebug.js两行代码即可可看下面图
定位到asdebug.js文件
打开搜索关键字URL 域名不合法关键字就是提示错误信息注释两行代码
主要方法:
wxml
<button type="primary" bindtap="listenerButtonDownLoadFile">下载图片</button> <image src="{{resource}}" style="width:100%; height: 80%"/> |
js
Page({ data:{ // text:"这是一个页面" resource: '' }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 }, /** * 下载文件 */ listenerButtonDownLoadFile: function() { var that = this; wx.downloadFile({ url: 'https://t2.27270.com/uploads/tu/201609/240/1mb2dybkw2x.jpg', type: 'image', success:function(res){ console.log(res.tempFilePath); that.setData({ resource: res.tempFilePath, }) }, fail:function(err){ console.log(err) }, complete:function(e) { console.log(e) } }) } }) |
二:wx.uploadFile(object), wx.downloadFile(object) API
反正我是没有测通这两个API!!!!不知道用的方式不对还是其他的!!!先记录下回头再说。。。
主要方法:
wx.uploadFile(OBJECT)上传
wx.downloadFile(OBJECT)下载
wxml
<button type="primary" bindtap="listenerButtonDownLoadFile">下载图片button> <image src="{{resource}}" style="width:100%; height: 80%"/> |
js
Page({ data:{ // text:"这是一个页面" resource: '' }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 }, /** * 下载文件 */ listenerButtonDownLoadFile: function() { var that = this; wx.downloadFile({ url: 'https://t2.27270.com/uploads/tu/201609/240/1mb2dybkw2x.jpg', type: 'image', success:function(res){ console.log(res.tempFilePath); that.setData({ resource: res.tempFilePath, }) }, fail:function(err){ console.log(err) }, complete:function(e) { console.log(e) } }) } }) |