Wednesday, March 3, 2021

Vue.js continued...

 Vue.js is a progressive framework for building user interfaces. It is one of the most popular JavaScript frameworks to make it easy to build user interfaces from the ground up in an incremental manner. The core library is a view-only framework and as such can be linked into web pages directly from a content data network. For example, if we want to build a feedback or survey solicitation system, the pervious post and its continuation now  will help us get started. 

The view state can be maintained to avoid re-rendering. This requires the use of a keep-alive directive surrounding the component Together with data, methods, and state, the vue instance can be successfully tested in all three forms: unit-testing, component testing, and end-to-end testing.  

Vue brings the best of other web frameworks such as Python Django and Java Spring. There is a router library available that supports nested route/view mapping, modular, component-based router configuration, route params, query, wildcards, View transition effects, Fine-grained navigation control, Links with automatic active CSS classes, HTML5 history, and Customizable Scroll behavior.  There is a loader for webpack that allows other webpack loaders such as Sass loader for style and Pug loader for the template. Custom loader chains can be applied to custom blocks in a .vue file.  These are automatically invoked with mere compliance to conventions. 

When we build a feedback or survey system, we simply define the template to comprise the component items we want to show. For example, a five-star feedback rating system will comprise of those five stars as radio controls that can be turned on in sequence on mouse hover and all of them can be specified together in a single vue file importing the corresponding ‘vue-star-rating’ module.  

Conclusion: The framework provides incrementally adoptable components that can be mixed and matched to create a view and complex controls, logic and workflow can be broken down and packaged into granular and reusable components. 

 

Reference: 

  1.  The index.html for a rudimentary Vue.js application: 

<template> 

  <div id="app"> 

    <img src="./assets/logo.png"> 

  </div> 

</template> 

  

<script> 

import StarRating from 'vue-star-rating' 

  

export default { 

  components: { 

    StarRating 

  }, 

  methods: { 

    setRating: function(rating){ 

      this.ratingrating; 

    } 

  }, 

  data: { 

    rating: 0 

  }, 

  template: ' \ 

        <table> \ 

        <tr> \ 

        <td> \ 

        <table><tr><td> \ 

        <p>Feedback basis:</p> \ 

        <star-rating :rating="1" :max-rating="1" :show-rating="false"></star-rating> \ 

        <p>5.0<span class="subscript">/5</span></p> \ 

        </td></tr></table> \ 

        </td> \ 

        <td> \ 

        <p> Rate this package </p> \ 

        <star-rating @rating-selected ="setRating" \ 

            :rounded-corners="true" \ 

            :border-width="4" \ 

            :padding="3" \ 

            :animate="true" \ 

            :star-points="[23,2, 14,17, 0,19, 10,34, 7,50, 23,43, 38,50, 36,34, 46,19, 31,17]"></star-rating> \ 

        </td></tr></table>' 

} 

  

</script> 

  

<style> 

#app { 

  font-family: 'Avenir', Helvetica, Arial, sans-serif; 

  -webkit-font-smoothing: antialiased; 

  -moz-osx-font-smoothing: grayscale; 

  text-align: center; 

  color: #2c3e50; 

  margin-top: 60px; 

} 

</style> 

 

 

Tuesday, March 2, 2021

Vue.js

 Writing an application with Vue: 

Introduction: Vue.js is a progressive framework for building user interfaces. It is one of the most popular JavaScript frameworks to make it easy to build user interfaces from the ground up in an incremental manner. The core library is a view-only framework and as such can be linked into web pages directly from a content data network. For example, if we want to build a feedback or survey solicitation system, the following article will help us get started. 

 

Description:  A sample web page to be written in Vue could start with just the template, style, and script as shown in reference 1. All of this can be on the same web page but Vue provides excellent integration with many other frameworks so it is easy to package code in single file components that end with the .vue extension. These can then be combined into the main page with the help of component declaration and use. Each view file allows specifying a template, script, and style snippet. 

 

A Vue instance consists of a root Vue instance and includes a tree of nested, reusable components when the application is well-organized. The instance created with a dictionary for data and methods which tells the Vue’s reactivity system how to respond when the data changes from the user interface. There is a 'freeze' method available that can prevent the existing properties from being changed but for the most part, a vue instance responds to the user’s directives. 

 

As with all user interfaces, the Vue instance goes through a lifecycle and there are hooks available such as mounted, updated, and destroyed so that the stages can be switched. All lifecycle hooks are called with their ‘this’ context pointing to the Vue instance invoking it. 

 

The syntax used to describe the template, style and scripts do not change from what the HTML expects them to be. The data binding happens with the “Mustache” syntax and can include raw HTML with the v-html directive. List rendering occurs with an iteration over an array specified with the v-for directive. Filtering happens with the v-if directive. 


A working-sample application: https://1drv.ms/u/s!Ashlm-Nw-wnWyB2rx30dmeEoNxt_?e=ZHiGjt