vuejs2 - Vue js : _this.$emit is not a function -
i have created vue component call imageupload , pass property v-model
<image-upload v-model="form.image"></image-upload>
and within imgeupload component have code
<input type="file" accept="images/*" class="file-input" @change="upload">
upload:(e)=>{ const files = e.target.files; if(files && files.length > 0){ console.log(files[0]) this.$emit('input',files[0]) } } and received
uncaught typeerror: _this.$emit not function thanks
do not define method fat arrow. use:
upload: function(e){ const files = e.target.files; if(files && files.length > 0){ console.log(files[0]) this.$emit('input',files[0]) } } when define method fat arrow, capture lexical scope, means this pointing window, , not vue.
Comments
Post a Comment