Wednesday, February 16, 2022
Image preview in vue js
<div id="app">
<div class="container">
<h1>Vue.js Image Preview</h1>
<input type="file" @change="onFileChange" accept="image/*">
<output>
<img :src="previewUrl" v-if="previewUrl">
<p v-else>No image...</p>
</output>
</div>
</div>
var app = new Vue({
el: '#app',
data: {
previewUrl: ''
},
methods: {
onFileChange: function (event) {
const file = event.target.files[0]
if (!file) {
return false
}
if (!file.type.match('image.*')) {
return false
}
const reader = new FileReader()
const that = this
reader.onload = function (e) {
that.previewUrl = e.target.result
}
reader.readAsDataURL(file)
}
}
})
Subscribe to:
Posts (Atom)
-
Composer is a major part of the Laravel MVC Framework, but it also exists without Laravel. In fact you could use it in any project. This a...
-
How to Answer Technical Questions Like a Pro Answering technical interview questions is all about showing off your problem-solving skills an...
-
Vuetify is a popular UI framework for Vue apps. In this article, we’ll look at how to work with the Vuetify framework. Color Picker Inputs W...