Created
April 19, 2020 20:40
-
-
Save danyal14/8ab7898d3e60acac6aac9ec7ebd8a5dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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