M
M
myskypesla2018-07-06 10:13:08
Vue.js
myskypesla, 2018-07-06 10:13:08

How to make a filter in template?

There is this code:

<template>
  <ul>
    <li v-for="item in items">
      <span>{{ item.date }}</span>
    </li>
  </ul>
</template>

And as a result, the following date formats come:
2018-10-26T20:00:00
And you need this format:
10/26/2018
Question: how to change the format and remove the excess?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Anton, 2018-07-06
@myskypesla

With the help of moment.js: https://codepen.io/anon/pen/aKgLXP
The only thing, if you build using webpack, then you need to remove unnecessary locales from the build, otherwise everything will be very bold. More or less like this:

const webpack = require('webpack');
....
module.exports = {
  ...,
  plugins: [
    new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /ru/),
  ],
...
}

V
Vladimir Proskurin, 2018-07-06
@Vlad_IT

Computed property or directives https://ru.vuejs.org/v2/guide/custom-directive.html

A
Argumentus, 2018-07-06
@Argumentus

Computed property advice sucks, use https://en.vuejs.org/v2/guide/filters.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question