Im whatching a vue.js course and the presentator use this code for an if/else stament on the vue component. Please if someone can tell me, to understand a way more better the code, im be appreciative.
<template>
<!-- ? = if // : = else -->
<div :>
<h3>{{ task.text }}
<i ></i>
</h3>
<p>{{ task.day }}</p>
</div>
</template>
CodePudding user response:
<div :>
source: https://v2.vuejs.org/v2/guide/class-and-style.html#Array-Syntax
this line will conditionally add array of class that will be joined by a space
. So on the first element of the array, it is a ternary operator which depend on task.reminder
value, if it is true
or something meet the requirement of the ternary, it will add reminder
class or an empty string ''
which will not be added to the class, and on the index 1
of the array which is task
will be added.
Say for example that your task.reminder
is true
, the div will be render as below:
<div >
if it is false, it will be render as
<div >
{{ task.text }}
source: https://v2.vuejs.org/v2/guide/syntax.html?redirect=true#Text
this is how we render out a variable from vue into the DOM, wrap with {{
and }}