question-12
Bastien JACQUELIN 2 years ago
parent c6d76d18c4
commit 388bf4a194

@ -11,7 +11,7 @@
<h1>TP-noté</h1> <h1>TP-noté</h1>
<nav-bar @add-team="addTeam"></nav-bar> <nav-bar @add-team="addTeam"></nav-bar>
<team-card v-for="team in teams" <team-card @edit-team="editTeam" v-for="team in teams"
:id="team.id" :id="team.id"
:nom="team.name" :nom="team.name"
:description="team.description"> :description="team.description">
@ -30,14 +30,30 @@
created(){}, created(){},
data(){ data(){
return{ return{
teams: [] teams: [],
edit:false,
newTeam:null
} }
}, },
methods:{ methods:{
addTeam: function(equipe){ addTeam: function(equipe){
console.log(equipe); if(!this.edit){//adding a team
this.teams.push(equipe); this.teams.push(equipe);
} }
else{//editing a team
this.teams.forEach((e,idx) => {
if(e.id==this.newTeam.id&&e.name==this.newTeam.name&&e.description==this.newTeam.description){
this.teams[idx]=equipe;
}
});
this.edit=false;
this.newTeam=null;
}
},
editTeam: function (team) {
this.newTeam=team;
this.edit=!this.edit;
}
} }
}); });

@ -1,19 +1,20 @@
export default{ export default{
emits: ['editTeam'],
props: { props: {
id: Number, id: Number,
nom: String, nom: String,
description: String description: String
}, },
methods: { methods: {
myfun: function() { edit: function() {
console.log('to do') this.$emit("editTeam", new Team(this.id,this.nom,this.description))
} }
}, },
template: ` template: `
<br> <br>
<div id="teamCard"> <div id="teamCard">
<span>{{id}} {{nom}} description: {{description}}</span> <span>{{id}} {{nom}} description: {{description}}</span>
<span @click="myfun" style="cursor: pointer"> - éditer</span> <span @click="edit" style="cursor: pointer"> - éditer</span>
</div> </div>
` `
} }

Loading…
Cancel
Save