April 2017
Intermediate to advanced
454 pages
12h 51m
English
Let's say we are curating an interactive page to learn history. We have our Vue instance with the following JavaScript code:
new Vue({ el:'#app', data: { bastilleStormingDate: '1789-07-14 17 h' } })
In our data, we have a date written informally as a string in our instance data. Our HTML can contain a timeline of the French Revolution and, at some point, can contain the following:
<div id="app"> The Storming of the Bastille, happened on {{bastilleStormingDate | date}} </div>
We need a filter capable of completing the sentence. For this, one possible library is the excellent moment.js and, for our purposes, we'll choose the localized version: https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment-with-locales.js ...