Conditional Rendering (ok)
Last updated
Last updated
<template>
<ul>
<h1>{{ title }}</h1>
<li v-for="task in tasks" :key="task.id">
{{ task.id }}. {{ task.name }}
<span v-if="task.finished">
<span style="color: red;">Delete task</span>
</span>
</li>
</ul>
</template>
<script>
export default {
data() {
return {
title: 'My To Do App',
tasks: [
{ id: 1, name: 'Learn Vue JS', finished: false },
{ id: 2, name: 'Build a Vue application', finished: true },
{ id: 3, name: 'Write an article about Vue JS', finished: false }
]
}
}
}
</script>
<template>
<ul>
<h1>{{ title }}</h1>
<li v-for="task in tasks" :key="task.id">
{{ task.id }}. {{ task.name }}
<span v-if="task.finished">
<span style="color: red;">Delete task</span>
</span>
<span v-else-if="task.edit">
<span style="color: red;">Edit task</span>
</span>
<span v-else="task.edit">
<span style="color: red;">Edit task</span>
</span>
</li>
</ul>
</template>
<script>
export default {
data() {
return {
title: 'My To Do App',
tasks: [
{ id: 1, name: 'Learn Vue JS', finished: false, edit: false, else: false},
{ id: 2, name: 'Build a Vue application', finished: true, edit: false, else: true },
{ id: 3, name: 'Write an article about Vue JS', finished: false, edit: true, else: false }
]
}
}
}
</script>