Raymond Camden

Developer Advocate for IBM

A few days ago I shared a simple Vue.js demo for an app called INeedIt. While not a terribly a complex application, it was something fun to build just to get some practice with Vue. Before I shared that post, I let my friend Ted Patrick take a look at the code and he had some feedback I thought would be nice to incorporate into a second version. I've made his suggested changes and I thought I'd quickly review them here. This is version two of the app and I've already got a third version of the app to share later. Anyway, here are the changes he suggested.

First, and this is the simplest, was a change in the script tags I used. The first version had this:

This will load the most recent version of Vue, and the Vue Router, but also has some delays in terms of loading. How much of a delay? Half a second. While that doesn't sound like much, every delay adds up, and switching to a specific version removes that delay. Here is the simple update:

The second change was more important and fixes an obvious bug in the first version. My initial version used the created event to request the user's location. Unfortunately, this ran every time the route was loaded as the component was created each time the view was shown. Ted suggested a simple change to the code that addressed this.

He moved the data for the component (which included a few flags, the set of services, and the location) into the global scope. So the top of my app.js now has this: