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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -