Book Image

Vue.js 2 Cookbook

By : Andrea Passaglia
Book Image

Vue.js 2 Cookbook

By: Andrea Passaglia

Overview of this book

Vue.js is an open source JavaScript library for building modern, interactive web applications. With a rapidly growing community and a strong ecosystem, Vue.js makes developing complex single page applications a breeze. Its component-based approach, intuitive API, blazing fast core, and compact size make Vue.js a great solution to craft your next front-end application. From basic to advanced recipes, this book arms you with practical solutions to common tasks when building an application using Vue. We start off by exploring the fundamentals of Vue.js: its reactivity system, data-binding syntax, and component-based architecture through practical examples. After that, we delve into integrating Webpack and Babel to enhance your development workflow using single file components. Finally, we take an in-depth look at Vuex for state management and Vue Router to route in your single page applications, and integrate a variety of technologies ranging from Node.js to Electron, and Socket.io to Firebase and HorizonDB. This book will provide you with the best practices as determined by the Vue.js community.
Table of Contents (19 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Dedication
Preface

Formatting dates with filters


Sometimes you need a slightly more powerful filter than a basic one. You have to use similar filters many times, but every time with a slight variation. Having too many filters can create confusion. This example with dates will illustrate the problem and the solution.

Getting ready

Before moving ahead, make yourself more comfortable with filters by going through the Formatting your text with filters recipe in Chapter 1Getting started with Vue.js ; if you already know filters, keep reading.

How to do it...

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 ...