Home > Mobile >  v-if and v-else directives to show created and updated dates
v-if and v-else directives to show created and updated dates

Time:11-04

I have a django model which stores created and updated date on my front end i have a header called Date in my vue headers i am displaying the created date but i need to display the updated date under the same header when an object is updated. i have same date called row.updated_date_formatted if this is none i need to display created_date else i need to display updated date

 <template slot="row" slot-scope="{ row, index }">
   <td v-text="row.created_date_formatted"> </td>
  </template>

CodePudding user response:

You can code your logic right in v-text parameter value with Vue. Something like this:

<td v-text="row.updated_date_formatted != null ? row.updated_date_formatted : row.created_date_formatted"></td>

Or the same with Mustache syntax:

<td>{{row.updated_date_formatted != null ? row.updated_date_formatted : row.created_date_formatted}}</td>

v-if v-else is not really necessary in this case.

  • Related