yandere_fe/src/components/importer/importer.js

54 lines
1016 B
JavaScript
Raw Normal View History

const Importer = {
2019-03-30 02:10:57 -07:00
props: {
submitHandler: {
type: Function,
required: true
},
submitButtonLabel: {
type: String,
default () {
return this.$t('importer.submit')
}
},
successMessage: {
type: String,
default () {
return this.$t('importer.success')
}
},
errorMessage: {
type: String,
default () {
return this.$t('importer.error')
}
}
},
data () {
return {
file: null,
error: false,
success: false,
2019-03-30 02:10:57 -07:00
submitting: false
}
},
methods: {
change () {
this.file = this.$refs.input.files[0]
},
submit () {
2019-03-30 02:10:57 -07:00
this.dismiss()
this.submitting = true
this.submitHandler(this.file)
.then(() => { this.success = true })
.catch(() => { this.error = true })
.finally(() => { this.submitting = false })
},
dismiss () {
this.success = false
this.error = false
}
}
}
export default Importer