In my search for a substitute for MomentJS, which has been declared obsolete with no likely replacement, I came across particularly the ultralightweight DayJS. DayJS does not seem to be as feature-rich, but it tends to be much simpler, easier for installation, as well as usage. To connect DayJS to Vue, I will be using a particular wrapper installation kit.
Installing and setting up DayJS with Vue
To begin, install vue-dayjs from specifically the command line as normal.
Once installed, you would want to create a DayJS instance onto your Vue object. I have been just using Laravel as the overall project approach, but anything similar could fit with your Vue project.
A lightweight wrapper for combining dayjs with Vuejs.
Also Read: Top Reasons Why Vue.js Is Becoming the Most Trending JS-based Framework in 2021
Allow me to demonstrate. The wrapper comes with some of the default language, filter, as well as directive settings that are mentioned in the configuration documentation and that I have used (except for the language)
- filters ago seems to be the program’s default (and therefore only defined) filter. It is fairly straightforward; it takes out a date and then adds ago to particularly the end, for example A few days back
Countdown seems to be the package’s norm, much as filters (it is therefore only directive). Countdown does exactly as it claims it does: it counts down somehow to a certain date and period.
This displays the available time in the days, hours, minutes, as well as seconds, counting down as it goes.
This completes the download and walkthrough of the particular vue-dayjs fundamentals.
This completes the download and walkthrough of the particular vuejs-dayjs fundamentals.
DayJS, like MomentJS, could be used in a quite native environment. Simply enter a date into the DayJS constructor.
It returns a date relative value to particularly an optionally specified date, but it corresponds to the current date. The following are some examples of performance from the diffForHumans method:
– About 5 minutes ago
– A week ago
– The Same Year
Using the particular fromNow function in the Moment.js, we will do the actual same thing. Given that Day.js and Moment.js are expected to have the very same API, I thought that the fromNow approach will “just function.”
It turned out that it didn’t. However, with a few minor modifications to our code, we could get the very same fromNow approach to function with Day.js.
Thanks for reading our post “Installing and setting up DayJS with Vue”, please connect with us for any further inquiry. We are Next Big Technology, a leading web & Mobile Application Development Company. We build high-quality applications to full fill all your business needs.