Vue.js TypeError:无法读取属性';0';尝试记录我的$refs时的未定义值
我不知道我错在哪里,但我的控制台上写着: TypeError:无法读取未定义的属性“0” 在VueComponent.selectFile(vSingleUpload.vue?cf02:23)中 但在我的UI中,它不会崩溃,也不会呈现任何没有错误的内容Vue.js TypeError:无法读取属性';0';尝试记录我的$refs时的未定义值,vue.js,vuejs2,Vue.js,Vuejs2,我不知道我错在哪里,但我的控制台上写着: TypeError:无法读取未定义的属性“0” 在VueComponent.selectFile(vSingleUpload.vue?cf02:23)中 但在我的UI中,它不会崩溃,也不会呈现任何没有错误的内容 导出默认值{ 数据(){ 返回{ 档案:“ }; }, 方法:{ selectFile:function(){ this.file=this.$refs.userFile.files[0]; } } }; v-file-input不公开文件属
导出默认值{
数据(){
返回{
档案:“
};
},
方法:{
selectFile:function(){
this.file=this.$refs.userFile.files[0];
}
}
};
v-file-input
不公开文件
属性,因此此。$refs.userFile.files
将未定义
您可以直接获取文件作为传递给事件侦听器的参数,如下所示:
newvue({
el:“#应用程序”,
vuetify:新的vuetify(),
方法:{
选择文件(文件){
console.log(文件)
}
}
})
<template>
<section>
<v-content>
<v-container>
<v-form enctype="multipart/form-data">
<v-file-input label="file input" type="file" @change="selectFile" ref="userFile"></v-file-input>
</v-form>
</v-container>
</v-content>
</section>
</template>
<script>
export default {
data() {
return {
file: ""
};
},
methods: {
selectFile: function() {
this.file = this.$refs.userFile.files[0];
}
}
};
</script>
<style lang="scss">
</style>