save-image-to-photos-album.uvue 1.0 KB
Newer Older
张磊 已提交
1
<template>
H
hdx 已提交
2 3 4
  <!-- #ifdef APP -->
  <scroll-view style="flex:1">
  <!-- #endif -->
5
    <image src="/static/uni.png" style="margin: 15px 100px;height:196px;width:196px;align-self:center;"></image>
H
hdx 已提交
6 7 8 9
    <button style="margin: 15px;" @click="saveImage">将图片保存到手机相册</button>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
张磊 已提交
10 11 12
</template>

<script>
H
hdx 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  export default {
    data() {
      return {
      }
    },
    methods: {
      saveImage() {
        uni.saveImageToPhotosAlbum({
          filePath: "/static/uni.png",
          success() {
            uni.showToast({
              position: "center",
              icon: "none",
              title: "图片保存成功,请到手机相册查看"
            })
          },
          fail(e) {
            uni.showModal({
              content: "保存相册失败,errCode:" + e.errCode + ",errMsg:" + e.errMsg + ",errSubject:" + e.errSubject,
              showCancel: false
            });
          }
        })
      }
    }
  }
张磊 已提交
39 40 41
</script>

<style>
DCloud-yyl's avatar
DCloud-yyl 已提交
42
</style>