<template>
  <div>
    <el-upload
      action="http://192.168.110.67/mall/file/image/upload"
      list-type="picture-card"
      :on-preview="handlePictureCardPreview"
      :on-remove="handleRemove"
      :on-success="handleAvatarSuccess"
      :headers="headers"
      :file-list="fileList"
      :limit="1"
      :multiple ="false"
    >
      <i class="el-icon-plus"></i>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt />
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:{
    fileList:{
      type:Array,
      default:[
        {
          name: "",
          url: "",
        },
      ]
    },
  },
  data() {
    return {
      dialogImageUrl: "",
      dialogVisible: false
    };
  },
   computed: {
    headers() {
    //   return { 'token': this.backToken }
    return {'Authorization':localStorage.getItem('backToken')}
    }
  },
  methods: {
    // 图片上传成功的返回值
    handleAvatarSuccess(res, file) {
        console.log(res)
        // console.log(res.url)
        console.log(res.data.url)
        this.$emit('qrcodeUrl', res.data.url)
        // this.imageUrl = URL.createObjectURL(file.raw);
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    }
  }
};
</script>

<style>
</style>