Erreur complete

master
Raphael LACOTE 2 years ago
parent 0eae5e9958
commit 2dd4f01847

@ -1,5 +1,5 @@
class RequiredFieldError extends Error {
constructor(field) {
super('Le champ ${field} est obligatoire !');
super('Le champ '+field+' est obligatoire !');
}
}

@ -1,11 +1,10 @@
export default {
template:`
<section>
template:
`<section>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Teams</a></li>
<li><a href="#">Results</a></li>
</ul>
</section>
`
</section>`
};

@ -8,20 +8,32 @@ export default {
}
},
methods: {
addTeam: function() {
this.errorMessage = '';
if (!this.id || !this.name) {
this.errorMessage = 'ID and Name are required !';
return;
}
addTeam: function () {
try {
this.errorMessage = '';
if (!this.id) {
throw new RequiredFieldError("ID");
return;
}
if (!this.name) {
throw new RequiredFieldError("Name");
return;
}
const team = { id: this.id, name: this.name };
console.log('form.addTeam', team);
const team = { id: this.id, name: this.name};
console.log('form.addTeam', team);
this.$emit('addTeam', team);
this.$emit('addTeam', team);
this.id = '';
this.name = '';
} catch (error) {
if (error instanceof RequiredFieldError) {
this.errorMessage=error
}
this.id = '';
this.name = '';
return null;
}
}
},
template: `<section>

Loading…
Cancel
Save