<template>
  <div :style="{ width, height }" class="qs-picture-preview">
    <el-image v-if="previewUrl" :src="previewUrl" fit="fill"></el-image>
    <nm-icon class="no-picture" v-else name="photo" />
  </div>
</template>
<script>
// 接口
const api = $api.base.uploader

export default {
  data() {
    return {
      previewUrl: ''
    }
  },
  props: {
    url: {
      type: String
    },
    width: {
      type: String,
      default: '100px'
    },
    height: {
      type: String,
      default: '100px'
    }
  },
  methods: {
    get() {
      if (this.url) {
        api.preview(this.url).then(url => {
          this.previewUrl = url
        })
      } else {
        this.previewUrl = ''
      }
    }
  },
  mounted() {
    this.get()
  },
  watch: {
    url() {
      this.get()
    }
  }
}
</script>
<style lang="scss">
.qs-picture-preview {
  display: block;
  img {
    width: 100%;
  }
}
</style>
