The Vue introductory tutorial video

Posted by Lemeechi on 2019-05-11 13:46:57 in Discovery Vue Journal (543 views)

1904162

That 5-minute video that starts on clicking created a video at vuejs.org/v2/guide/index.html actually took a lot longer than five minutes for me to complete as I was coding the application being demonstrated as I went along.

The video demonstrated the following concepts and features.

  1. {{item}} Referencing Vue variables in HTML. Instantiating the Vue object.
  2. Adding more parameters in the Vue object instance declaration, following data: created(), and computed, although the created() method that was supposed to fetch data from a server did not work. The computed item defined a function that summed up one column of an array, the total product quantities.
  3. v-for="product in products" Inside the <li> tag, loops through an array (products) to display different child items (each named product).
  4. v-model.number="product.quantity" Binding a numeric variable with an HTML input element.
  5. v-if="product.quantity===0" For conditional display of an HTML element; this was specified on a <span> element to show "OUT OF STOCK" when quantity was zero.
  6. @click="product.quantity+=1" event action for a button element: adding 1 to product quantity.

Vue also has a command line interface (CLI), where you can type for instance, vue init webpack myproject at command prompt to initialize files for a project.

The application demonstrated in the video was supposed to show something like this (see above).

The total products was supposed to change accordingly. But after coding it didn’t work as such. I later took time out to investigate and debug the issues. There were two major issues I wanted to resolve, the non-display of the product quantity sum, and non-display of data fetched from a server. After a lot of trials and exploration I fixed both issues.

The sum product quantity was not displaying because of misspelling, my writing totalProduts instead of totalProducts. It was from the browser console that I saw the complaint about it. And the server data that was fetched didn’t display because it wasn’t the right data: I’d written 74163 (numeric) in the URL instead of 74l63 (alphanumeric).

To resolve that server data issue I had to visit myjson.com and read about their service. The portion of the code that referenced the site was

  created(){
    fetch("https://api.myjson.com/bins/74163")
      .then(response=>response.json())
      .then(json=>{
        this.products=json.products
    })
  } 

Myjson is a place you store and retrieve JSON data for use in client-side web and/or mobile applications. To put your JSON data there you simply copy and paste it into the main input window, then you can access your data through the provided link.

As I was checking I visited the link I had typed in the code above and it gave me the following.

 {"editors":{"main":"int a = 0;
int b = 1;

int c = a + b;","harness":"WebAssembly.instantiate(wasmCode, {/* imports */}).then(({instance}) =u003e {
  var memory = instance.exports.memory;
  // call any exported function, e.g. instance.exports.main()
  log(Object.keys(instance.exports));
});"},"compilerOptions":"-Os"} 

That wasn’t a product list at all. It was later that I wondered if I typed the address correctly. The data returned depended on an ID in the link, the value after bins/. I used alpha l (small L) instead of digit 1 and https://api.myjson.com/bins/74l63 returned the following:

 {"products":[{"id":1,"quantity":1,"name":"Compass"},{"id":2,"quantity":0,"name":"Jacket"},{"id":3,"quantity":5,"name":"Hiking Socks"},{"id":4,"quantity":2,"name":"Suntan Lotion"}]} 

This was the right JSON string result. I made the change in the code and then created() was now working because its fetch() was getting the right data.

I also installed the Vue DevTools for Firefox, useful for debugging from the browser console. Later visited www.vuemastery.com/courses/intro-to-vue-js/vue-instance/ from the last page of the introductory video where I had to register to be able to download the first video there, Vue Instance. The video was just playing on the page with no control options.

Summary

That 5-minute video that starts on clicking created a video at vuejs.org/v2/guide/index.html actually took a lot longer than five minutes for me to complete as I was coding the application being demonstrated as I went along. And after the coded app didn’t work as expected, I went on a successful debugging trip...

If you like this post please register or log in to be able to subscribe and be notified of new posts by Lemeechi.

 

Tags

2019    JSON    Lemeechi    May 2019    Myjson    myjson.com    Vue    Vue CLI    Vue DevTools    Vue DevTools for Firefox    Vue Mastery    VueJS    vuejs.org   

Comments

"I want to to thank you for this wonderful read!! I absolutely loved every little bit of it. I have got you book marked to check out new things you postO" https://tinyurl.com/y96gax6n

[by VictorAbisk45678 at 2022-01-20 04:38:52] 

Hello YOU NEED QUALITY VISITORS FOR YOUR: microsoftwareresearch.com ? We Provide Website Traffic 100% safe for your site, from Search Engines or Social Media Sites from any country you want. With this traffic, you can boost ranking in SERP, SEO, profit from CPM CLAIM YOUR 24 HOURS FREE TEST HERE=> http://griffinglru63963.bloggerbags.com/8099334/get-quality-visitors-for-your-site Thanks, Shela Guffey

[by Shela Guffey at 2021-12-20 09:55:04] 

Hi There! We are reaching out to those from the math education space who would be excited to participate in our FREE Virtual Summit coming up on November 13th and 14th, 2021. Not only will you love hearing 25+ influencers from the math education space presenting live over Zoom, but I'm sure your audience and colleagues will stand to benefit as well! Register to save your seat here: https://zeep.ly/GwPnv Will we see you there? Kyle & Jon admin@makemathmoments.com https://zeep.ly/GwPnv PS - Consider sharing this amazing free event with others in the education space!

[by Holly Marriott at 2021-11-01 11:40:19] 

Add Comment

(All values are required.)

 (Will not be published.)

Similar Posts

April 2019 In Brief  |   Discovery Vue Journal: Getting Started!  |   The Vue Mastery introductory course, Part 2  |   The Vue Mastery introductory course, Part 1  |   The Vue JS crash course by Traversy  |   May 2019 In Brief  |  

 Close
Tweet