话不多说上代码
<div id="app">
<input @change="uploadFile" type="file"></input>
<img :src="imgSrc" alt="">
</div>
<script>
var vm = new Vue({
el:'#app',
data: {
imgSrc: '',
},
methods: {
uploadFile(e) {
let url = '';
let file = window.webkitURL.createObjectURL(e.target.files[0])
if (window.createObjectURL!=undefined) {
url = window.createObjectURL(file);
} else if (window.URL!=undefined) {
url = window.URL.createObjectURL(file);
} else if (window.webkitURL!=undefined) {
url = window.webkitURL.createObjectURL(file);
}
this.imgSrc = url;
}
}
})
</script>