vant/packages/uploader/index.vue
neverland ffa3fddfae
[bugfix] remove unnecessary props (#323)
* fix: Tabbar icon line-height

* [new feature] progress add showPivot prop

* [new feature] TabItem support vue-router

* [new feature] update document header style

* [Doc] add toast english ducoment

* [bugfix] Search box-sizing wrong

* [Doc] update vant-demo respo

* [Doc] translate theme & demo pages

* [Doc] add Internationalization document

* [bugfix] remove unnecessary props
2017-11-16 03:12:13 -06:00

51 lines
1.0 KiB
Vue

<template>
<div class="van-uploader">
<slot></slot>
<input type="file" @change="onValueChange" :disabled="disabled" class="van-uploader__input" ref="input" />
</div>
</template>
<script>
export default {
name: 'van-uploader',
props: {
disabled: Boolean,
beforeRead: Function,
afterRead: Function,
resultType: {
type: String,
default: 'dataUrl'
}
},
methods: {
onValueChange(event) {
if (this.disabled) {
return;
}
const file = event.target.files[0];
if (!file || (this.beforeRead && !this.beforeRead(file))) {
return;
}
const reader = new FileReader();
reader.onload = (e) => {
this.afterRead && this.afterRead({
file,
content: e.target.result
});
this.$refs.input && (this.$refs.input.value = '');
};
if (this.resultType === 'dataUrl') {
reader.readAsDataURL(file);
} else if (this.resultType === 'text') {
reader.readAsText(file);
}
}
}
};
</script>