I have Vue application which has a array of errors in data object. Problem is that I can not set errors array to empty []. I try to set it in the begining of validation function but previous items still remain there. This is the code:
<div v-if="uploadErrors && uploadErrors.length" class="has-text-danger">
<div v-for="(error, index) in uploadErrors" :key="index" class="is-size-7">{{error}}</div>
</div>
data() {
return {
uploadErrors: [],
}
},
validateUploadFiles(files) {
this.uploadErrors = [];
console.log(this.uploadErrors); // uploadErrors still contains previous items
files.forEach( file => {
const foundFormat = this.allowedFormats.find( format => format.mimeType === file.type );
const isBigger = this.maxSize * 2 ** 20 < file.size;
if( isBigger ) this.uploadErrors.push( this.$t("campaign.upload.size_limit") );
if( !foundFormat ) this.uploadErrors.push( this.$t("campaign.upload.format") + ' ' + file.name );
});
console.log(this.uploadErrors); // uploadErrors still contains previous items
}
What is wrong with that? I dont understand.