yassine j
yassine j

Reputation: 515

I can't compare my date using MomentJs and Vue

I would like to find if my duration is > 0. I use MomentJs and Vue to get my duration using this code :

 moment3: function (date) {
  var now = moment();
  var day = moment(date);
  var duration = day.diff(now);
   return parseInt(duration);
  },

I get the duration correctly (2987546325 in example). But still this code not working.

<a v-if="event.time | moment3 > 0"> Do somethingHere </a>

Thank you for help.

Upvotes: 0

Views: 203

Answers (1)

skirtle
skirtle

Reputation: 29092

I assume that you're trying to use moment3 as a Vue filter function.

There are two problems here:

  1. You can't use a filter function in a v-if expression. They're only available inside a {{ ... }} or a v-bind expression.
  2. You can't put anything after a filter function, other than the function's arguments or another filter function. So the > 0 isn't allowed even if you were in a {{ ... }} or v-bind.

See https://v2.vuejs.org/v2/guide/filters.html

The | character will just be interpreted as JavaScript's bitwise OR operator in this case.

You'd probably be better off just using a method instead. So define moment3 inside your component's methods and then call it using v-if="moment3(event.time) > 0".

Upvotes: 2

Related Questions