<template>
  <input class="cust-upload" type="file" :accept="allowfile" @change="onchange" />
</template>

<script>
export default {
  name: 'fileUpload',
  props: [
    'accept',
    'value',
    'upload',
  ],
  data () {
    return {}
  },
  computed: {
    allowfile () {
      return this.accept || 'image/jpeg, image/gif, image/png'
    }
  },
  methods: {
    onchange (e) {
      const files = e.target.files
      if (files && files.length) {
        this.upload(files[0]).then((data) => {
          this.$emit('input', data)
        }).catch((error) => {
          // TODO
          console.log(error)
        })
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.cust-upload {

}
</style>
