Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
Integrating with Other Frameworks Chapter 19

You can even build a distributable version of the application with the npm run


build command.


How it works...


The way we implemented the timer is not particularly accurate for time tracking. Let's


review the code:


this.timer = setInterval(() => {
this.remainingTime -= 1
if (this.remainingTime === 0) {
clearInterval(this.timer)
}
}, 1000)

This means that we decrease the remaining time every second. The problem is that the


setInterval function itself is not 100% accurate and may fire the function a bit before or


after 1000 milliseconds, depending on the machine's computational load; this way, the


margin of error can accumulate and become a considerable amount. A better approach
would be to check the clock every time the function gets called and adjust for the error at


each loop, though we won't cover that here.


Using Vue with Firebase


Using Vue with Firebase as a backend is very easy, thanks to VueFire--a plugin that


contains bindings for Firebase. In this recipe, you will develop a fully functional database of
smells.


Getting ready


Firebase is out of the scope of this book, but I will assume, for this recipe, that you have a


familiarity with the basic concepts. Except for this, there is really not much you need to


know, as we will build a very basic Vue application on top of that.

Free download pdf