uni-app-------長按下載圖片

在遇到二維碼的頁面的時候,需要用到點擊二維碼圖片並保存在用戶手機中,讓用戶在相冊中找到這個二維碼

在html中對圖片添加點擊事件


<view  @longpress="saveImg()">
	<image src="http://qcxj.funnyworking.com/static/imges/mine/Customer_Service.png" mode='widthFix' ></image>
/view>

在js中需要調用兩個接口,第一個是用於下載圖片的接口,第二是用於保存圖片的接口

// 保存圖片
		saveImg(w){
			console.log(w)
			uni.downloadFile({      //下載圖片
				url:'http://qcxj.funnyworking.com/static/imges/mine/Customer_Service.png',
				success:(res)=>{
					console.log(res.tempFilePath)
					uni.saveImageToPhotosAlbum({     //將圖片保存在手機
						filePath:res.tempFilePath,     //保存的位置
						success: (res) => {
							console.log(res)
							console.log('長按保存圖片')
							
						}
					})
				}
			})
			
		},

就這樣可以簡單實現長按圖片並保存的效果

 

其餘功能之後更改。。。。。。。。。。。。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章