Load files to into application without backend in Vue

Read file as data URL:

#!html
<label class="input-group-btn">
	<span class="btn btn-warning">
		Find File&hellip; <input type="file" v-on:change="file_selected">
	</span>
</label>

Method:

file_selected(e) {
	var files = e.target.files || e.dataTransfer.files;
	if (!files)
		return;

	this.file_name = files[0].name;

	var reader = new FileReader();

	reader.onload = (e) => {
		this.file = e.target.result;
		this.error = "";
	};

	reader.readAsDataURL(files[0]);
},
#vuejs #javascript
0
Ivan Borshchov profile picture
Oct 31, 2016
by Ivan Borshchov
Did it help you?
Yes !
No

Best related