<template>
<view class="content u-flex-col u-col-center u-row-center">
<image :src="url" :data-url="url" mode="widthFix" class="height-100-per width-100-per" @longpress="toSave">
</image>
<view class="u-text-center u-p-20">長(zhǎng)安即可保存圖片</view>
</view>
</template>
<script>
export default {
data() {
return {
url:'../../static/mini_img.jpg',
}
},
onLoad() {
},
onShow() {
},
methods: {
toSave() {
uni.showModal({
title: '圖片保存',
content: '確定要保存圖片嗎',
success: res => {
if (res .confirm) {
this.save();
}
}
});
},
save() {
var that = this;
// #ifdef APP-PLUS
uni.getImageInfo({
src: that.url,
success: function(res) {
console.log('res', res);
uni.saveImageToPhotosAlbum({
filePath: res.path,
success: function() {
console.log('保存成功!');
uni.showToast({
title: '圖片保存成功',
icon: 'none',
duration: 1000
});
},
fail: (err) => {
console.log(err);
}
});
}
});
// #endif
},
}
}
</script>
<style>
html,
body,
.content,
uni-page-body,
wx-page-body {
height: 100%;
width: 100%;
}
.height-100-per{
height: 100%;
}
.width-100-per{
width: 100%;
}
</style>
saveImageToPhotosAlbum:fail auth deny 沒(méi)有存儲(chǔ)權(quán)限