微信小程序长按保存代码
时间: 2023-10-01 13:08:55 浏览: 56
长按保存图片:
```html
<image src="https://example.com/image.jpg" bindlongtap="saveImage"></image>
```
```javascript
saveImage: function (e) {
wx.showActionSheet({
itemList: ['保存图片'],
success: function (res) {
if (res.tapIndex === 0) {
wx.downloadFile({
url: e.currentTarget.dataset.src,
success: function (res) {
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function () {
wx.showToast({
title: '保存成功'
})
}
})
}
})
}
}
})
}
```
长按保存文字:
```html
<view bindlongtap="saveText">长按保存文字</view>
```
```javascript
saveText: function () {
wx.setClipboardData({
data: '需要保存的文字',
success: function () {
wx.showToast({
title: '已复制'
})
}
})
}
```