Skip to content

Instantly share code, notes, and snippets.

@danyal14
Created April 19, 2020 20:40
Show Gist options
  • Save danyal14/8ab7898d3e60acac6aac9ec7ebd8a5dc to your computer and use it in GitHub Desktop.
Save danyal14/8ab7898d3e60acac6aac9ec7ebd8a5dc to your computer and use it in GitHub Desktop.
<div id="demo">
<input type="text" v-model="text"> text: {{text}}
<input type="file" v-model="file"> file: {{file}}
</div>
ar vue = new Vue({
el: '#demo',
// default values
data: {
text: '',
file: ''
},
ready: function() {
// watch for file input on bootstrap
this.watchFileInput();
},
methods: {
watchFileInput: function() {
// will notify a file input
$('input[type="file"]').change(this.notifyFileInput.bind(this));
},
notifyFileInput: function(event) {
var fileName = event.target.files[0].name;
// update file name value
this.file = fileName;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment