This commit is contained in:
taiyong 2017-03-15 11:44:27 +08:00
parent b653859f61
commit 4346bf8c05
2 changed files with 13 additions and 19 deletions

View File

@ -23,7 +23,8 @@ module.exports = {
document: false,
navigator: false,
window: false,
require: true
require: true,
FileReader: true
},
rules: {

View File

@ -21,43 +21,36 @@
resultType: {
type: String,
default: 'dataUrl',
validator (value) {
return value == 'dataUrl' || value == 'text'
validator(value) {
return value === 'dataUrl' || value === 'text';
}
}
},
methods: {
onValueChange (event) {
onValueChange(event) {
if (this.disabled) {
return;
}
var files = event.target.files;
var file = files[0];
if (!file) return;
if (this.beforeRead && ! this.beforeRead(file)) return;
if (this.beforeRead && !this.beforeRead(file)) return;
var reader = new FileReader();
reader.onload = (e) => {
this.$emit('file-readed',
{
name:file.name,
type:file.type,
size:file.size,
content:e.target.result
name: file.name,
type: file.type,
size: file.size,
content: e.target.result
});
this.$refs.input.value = '';
};
if (this.resultType == 'dataUrl') {
if (this.resultType === 'dataUrl') {
reader.readAsDataURL(file);
} else if (this.resultType == 'text') {
} else if (this.resultType === 'text') {
reader.readAsText(file);
}
}
}
}
};