I just started learning Vue because I want to move from PHP to Javascript.
I have a question that I can't solved and I hope you can help me with it.
I have a list of tasks. I want to update the status if I pleted the task. If I click, the set as plete link, the task would move from the inplete tasks to the list of pleted tasks.
You can see on the screenshot, the Buy milk is in the pleted tasks. What I am trying to do is to add a "pleted" text or a check icon beside "Buy milk" on the All Task list.
Here is my code:
< script >
var app = new Vue({
el: '#root',
data: {
message: 'Hello world!',
tasks: [{
description: 'Go to the store',
pleted: false
},
{
description: 'Buy milk',
pleted: false
},
{
description: 'Feed the dog',
pleted: false
},
{
description: 'Cook something',
pleted: false
}
]
},
methods: {
setToCompleted() {
thispleted = true;
},
},
puted: {
inpleteTasks() {
return this.tasks.filter(task => !taskpleted);
},
pletedTasks() {
return this.tasks.filter(task => taskpleted);
}
}
}); <
/script>
<div id="root">
<h3>All tasks</h3>
<ul>
<li v-for="task in tasks" v-text="task.description == true ? 'Completed' : 'Not pleted'"></li>
</ul>
<h3>Inplete Tasks</h3>
<ul>
<li v-for="task in inpleteTasks">{{ task.description }} | <a href="#" @click="taskpleted = true">Set as pleted</a></li>
</ul>
<h3>Completed Tasks</h3>
<ul>
<li v-for="task in pletedTasks" v-text="task.description"></li>
</ul>
</div>
I just started learning Vue because I want to move from PHP to Javascript.
I have a question that I can't solved and I hope you can help me with it.
I have a list of tasks. I want to update the status if I pleted the task. If I click, the set as plete link, the task would move from the inplete tasks to the list of pleted tasks.
You can see on the screenshot, the Buy milk is in the pleted tasks. What I am trying to do is to add a "pleted" text or a check icon beside "Buy milk" on the All Task list.
Here is my code:
< script >
var app = new Vue({
el: '#root',
data: {
message: 'Hello world!',
tasks: [{
description: 'Go to the store',
pleted: false
},
{
description: 'Buy milk',
pleted: false
},
{
description: 'Feed the dog',
pleted: false
},
{
description: 'Cook something',
pleted: false
}
]
},
methods: {
setToCompleted() {
this.pleted = true;
},
},
puted: {
inpleteTasks() {
return this.tasks.filter(task => !task.pleted);
},
pletedTasks() {
return this.tasks.filter(task => task.pleted);
}
}
}); <
/script>
<div id="root">
<h3>All tasks</h3>
<ul>
<li v-for="task in tasks" v-text="task.description == true ? 'Completed' : 'Not pleted'"></li>
</ul>
<h3>Inplete Tasks</h3>
<ul>
<li v-for="task in inpleteTasks">{{ task.description }} | <a href="#" @click="task.pleted = true">Set as pleted</a></li>
</ul>
<h3>Completed Tasks</h3>
<ul>
<li v-for="task in pletedTasks" v-text="task.description"></li>
</ul>
</div>
What I have tried Is I added a condition on a v-text directive. But it always show not pleted. May you guide me why it is not changing? I would appreciate your help.
Thankyou.
EDIT======
This code solves my problem: thanks @tomrlh
<div id="root">
<h3>All tasks</h3>
<li v-for="task in tasks">
{{ task.description }} {{ task.pleted ? 'pleted' : '' }}
</li>
<h3>Inplete Tasks</h3>
<ul>
<li v-for="task in inpleteTasks">{{ task.description }} | <a href="#" @click="task.pleted = true">Set as pleted</a></li>
</ul>
<h3>Completed Tasks</h3>
<ul>
<li v-for="task in pletedTasks" v-text="task.description"></li>
</ul>
</div>
Share
Improve this question
edited Mar 3, 2019 at 6:00
Dan Angelo Alcanar
asked Mar 3, 2019 at 3:01
Dan Angelo AlcanarDan Angelo Alcanar
3792 gold badges3 silver badges13 bronze badges
1 Answer
Reset to default 13what about to check if the task is pleted in your All Tasks exhibition, then showing conditionally the 'pleted' message:
<h3>All tasks</h3>
<li v-for="task in tasks">
{{ task.description }} {{ task.pleted ? ' | pleted' }}
</li>