1.在標(biāo)簽里傳遞ID
1<text catchtap="handleDownload"?data-link="{{item.link}}">下載</text>
2.js下載方法
//下載
?handleDownload(e) {
???let?link = e.currentTarget.dataset.link;
???let?fileName =?new?Date().valueOf();
???wx.downloadFile({
?????url: link,
?????filePath: wx.env.USER_DATA_PATH +?'/'?+ fileName +?'.mp4',
?????success: res => {
???????console.log(res);
???????let?filePath = res.filePath;
???????wx.saveVideoToPhotosAlbum({
?????????filePath,
?????????success: file => {
???????????$Message({
?????????????content:?'下載成功',
?????????????type:?'success'
???????????})
???????????let?fileMgr = wx.getFileSystemManager();
???????????fileMgr.unlink({
?????????????filePath: wx.env.USER_DATA_PATH +?'/'?+ fileName +?'.mp4',
?????????????success:?function(r) {
?????????????},
???????????})
?????????},
?????????fail: err => {
???????????console.log(err)
???????????if?(err.errMsg ===?'saveVideoToPhotosAlbum:fail auth deny') {
?????????????wx.showModal({
???????????????title:?'提示',
???????????????content:?'需要您授權(quán)保存相冊',
???????????????showCancel:?false,
???????????????success: data => {
?????????????????wx.openSetting({
???????????????????success(settingdata) {
?????????????????????if?(settingdata.authSetting['scope.writePhotosAlbum']) {
???????????????????????wx.showModal({
?????????????????????????title:?'提示',
?????????????????????????content:?'獲取權(quán)限成功,再次點(diǎn)擊下載即可保存',
?????????????????????????showCancel:?false,
???????????????????????})
?????????????????????}?else?{
???????????????????????wx.showModal({
?????????????????????????title:?'提示',
?????????????????????????content:?'獲取權(quán)限失敗,將無法保存到相冊哦~',
?????????????????????????showCancel:?false,
???????????????????????})
?????????????????????}
???????????????????},
?????????????????})
???????????????}
?????????????})
???????????}
?????????}
???????})
?????}
???})
?},
https://blog.csdn.net/weixin_30407099/article/details/97398356
https://www.cnblogs.com/Glant/p/11423370.html