用input上传文件,change事件传参未定义?

新手上路,请多包涵
<input type="file" ref="upload" name="avatar" id='upload_input' accept="image/jpg" @change="upload($event)"/>


upload(e){
            var image = e.target.files[0];
            var uploadForm = new FormData();
            var author = this.$route.params.userMessage.username
            uploadForm.append('avatar', image, author);
            this.$axios.post('http://localhost/users/upload',{uploadForm})
            .then(function(res){
                // console.log(res);
                alert(res);
            })
        }

今天遇到一个奇怪的问题,上面是input标签和change事件的代码,一旦触发,浏览器控制台报错
Cannot read property 'target' of undefined

即事件里面的e.target.files[0]的target未定义,求大神解答。。

阅读 2.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题