Seminar Report Vyshnav
Seminar Report Vyshnav
JS
A SEMINAR REPORT
Submitted by
Mr. VAISHNAV MK
(19132319)
MALAPPURAM
CERTIFICATE
(Department seal)
VUE.JS
DECLARATION
Place: Malappuram
Date:
ACKNOWLEDGEMENT
I give all honor and praise to the GOD who gave me wisdom and enabled me to
complete my seminar on "FLASK WEB FRAMEWORK" successfully.Then I express
my sincere thanks to, Mr. ABDUL HAMEED C.P, Principal, MA’DIN polytechnic
college Malappuram, who permitted to make use of the college facilities such as the
Software Labs, Internet etc at maximum possible extent.
ABSTRACT
Vue (pronounced /vjuː/, like view) is a progressive framework for building user
interfaces. Unlike other monolithic frameworks, Vue is designed from the ground up to
be incrementally adoptable. The core library is focused on the view layer only, and is
easy to pick up and integrate with other libraries or existing projects. On the other hand,
Vue is also perfectly capable of powering sophisticated SinglePage Applications when
used in combination with modern tooling and supporting libraries.
CONTENTS
1 INTRODUCTION 06
2 VUEJS OVERVIEW 07
2.1 FEATURES 07
2.2 COMPARISON WITH OTHER 09
FRAMEWORK
2.3 VUEJS VS OTHERS 10
3 VUEJS-ENVIRONMENT SETUP 14
3.1 USING THE <SCRIPT> 14
3.2 USING CDN 14
4 VUEJS INTRODUCTION 16
4.1 EXAMPLE 17
4.2 OUTPUT 14
5 COMPUTED PROPERTIES 18
5.1 REMARKS 18
5.2 EXAMPLES 18
5.3 COMPUTED FEATURES VS WATCH 20
5.4 COMPUTED EXAMPLES 21
5.5 COMPUTED SETTERS 21
5.6 USING COMPUTED SETTERS 23
5.7 STYLING 24
6 CONDITIONAL RENDERING 28
6.1 REMARKS 28
6.2 V-SHOW 30
7 CUSTOM COMPONENTS WITH 32
V-MODEL
7.1 INTRODUCTION 32
8 CUSTOM DIRECTIVES 36
8.1 BASICS 36
8.2 DIRECTIVE INSTANCE PROPERTIES 37
9 CUSTOM FILTERS 41
9.1 TWO WAY FILTERS 41
9.2 BASICS 42
9.3 SYNTAX 43
10 DATA BINDING AND DYNAMIC 44
COMPONENTS
10.1 DATA BINDING 44
10.2 SIMPLE DYNAMIC COMPONENT 45
10.3 PAGES KEY WITH NAVIGATION ALIVE 47
11 CONCLUSIONS 50
CHAPTER 1
INTRODUCTION
To start using Vue.js, make sure you have the script file included in your HTML.
For example, add the following to your HTML.
<script src="https://npmcdn.com/vue/dist/vue.js"></script>
VueJS can be used to easily handle user input as well, and the two way binding
using v-model makes it really easy to change data easily.
CHAPTER 2
VUEJS OVERVIEW
2.1 FEATURES
Following are the features available with VueJS.
VueJS makes the use of virtual DOM, which is also used by other frameworks
such as React, Ember, etc. The changes are not made to the DOM, instead a replica
of the DOM is created which is present in the form of JavaScript data structures.
Whenever any changes are to be made, they are made to the JavaScript data
structures and the latter is compared with the original data structure. The final
changes are then updated to the real DOM, which the user will see changing. This
is good in terms of optimization, it is less expensive and the changes can be made
at a faster rate.
The data binding feature helps manipulate or assign values to HTML attributes,
change the style, assign classes with the help of binding directive called v-bind
2.1.3 ComponentS
Components are one of the important features of VueJS that helps create custom
elements, which can be reused in HTML.
v-on is the attribute added to the DOM elements to listen to the events in VueJS.
2.1.5 Animation/Transition
VueJS provides various ways to apply transition to HTML elements when they are
added/updated or removed from the DOM. VueJS has a built-in transition
component that needs to be wrapped around the element for transition effect. We
can easily add third party animation libraries and also add more interactivity to the
interface.
This is one of the important features of VueJS. It helps to listen to the changes
made to the UI elements and performs the necessary calculations. There is no need
of additional coding for this.
2.1.7 Templates
VueJS provides HTML-based templates that bind the DOM with the Vue instance
data. Vue compiles the templates into virtual DOM Render functions. We can
make use of the template of the render functions and to do so we have to replace
the template with the render function.
2.1.8 Directives
VueJS has built-in directives such as v-if, v-else, v-show, v-on, v-bind, and
v-model, which are used to perform various actions on the frontend.
2.1.9 Watchers
Watchers are applied to data that changes. For example, form input elements.
Here, we don’t have to add any additional events. Watcher takes care of handling
2.1.10 Routing
2.1.11 Lightweight
VueJS script is very lightweight and the performance is also very fast.
2.1.12 Vue-CLI
VueJS can be installed at the command line using the vue-cli command line
interface. It helps to build and compile the project easily using vue-cli.
Virtual DOM
Virtual DOM is a virtual representation of the DOM tree. With virtual DOM, a
JavaScript object is created which is the same as the real DOM. Any time a change
needs to be made to the DOM, a new JavaScript object is created and the changes
are made. Later, both the JavaScript objects are compared and the final changes
are updated in the real DOM. VueJS and React both use virtual DOM, which
makes it faster.
VueJS uses html, js and css separately. It is very easy for a beginner to understand
and adopt the VueJS style. The template based approach for VueJS is very easy.
React uses jsx approach. Everything is JavaScript for ReactJS. HTML and CSS are
all part of JavaScript.
Installation Tools
React uses create react app and VueJS uses vue-cli /CDN/npm. Both are very easy
to use and the project is set up with all the basic requirements. React needs
webpack for the build, whereas VueJS does not. We can start with VueJS coding
anywhere in jsfiddle or codepen using the cdn library.
Popularity
React is more popular than VueJS. The job opportunity with React is more than
VueJS. There is a big name behind React i.e. Facebook which makes it more
popular. Since, React uses the core concept of JavaScript, it uses the best practice
of JavaScript. One who works with React will definitely be a very good with all
the JavaScript concepts. VueJS is a developing framework. Presently, the job
opportunities with VueJS are less in comparison to React. According to a survey,
many people are adapting to VueJS, which can make it more popular in
comparison to React and Angular. There is a good community working on the
different features of VueJS. The vue-router is maintained by this community with
regular updates. VueJS has taken the good parts from Angular and React and has
built a powerful library. VueJS is much faster in comparison to React/Angular
because of its lightweight library
VueJS has a lot of similarities with Angular. Directives such as v-if, v-for are
almost similar to ngIf, ngFor of Angular. They both have a command line interface
for project installation and to build it. VueJS uses Vue-cli and Angular uses
angular-cli. Both offer two-way data binding, server side rendering, etc.
Complexity
Vuejs is very easy to learn and start with. As discussed earlier, a beginner can take
the CDN library of VueJS and get started in codepen and jsfiddle. For Angular, we
need to go through a series of steps for installation and it is little difficult for
beginners to get started with Angular. It uses TypeScript for coding which is
difficult for people coming from core JavaScript background. However, it is easier
to learn for users belonging to Java and C# background.
Performance
To decide the performance, it is up to the users. VueJS file size is much lighter
than Angular. A comparison of the framework performance is provided in the
following link
http://stefankrause.net/js-frameworks-benchmark4/webdriver-ts/table.html
Popularity
Dependencies
Angular provides a lot of built-in features. We have to import the required modules
and get started with it, for example, @angular/animations, @angular/form. VueJS
does not have all the built-in features as Angular and needs to depend on third
party libraries to work on it.
Flexibility
VueJS can be easily merged with any other big project without any issues. Angular
will not be that easy to start working with any other existing project.
Backward Compatibility
We had AngularJS, Angular2 and now Angular4. AngularJS and Angular2 have
vast difference. Project application developed in AngularJS cannot be converted to
Angular2 because of the core differences. The recent version of VueJS is 2.0 and it
is good with backward compatibility. It provides good documentation, which is
very easy to understand.
Typescript
Angular uses TypeScript for its coding. Users need to have knowledge of
Typescript to get started with Angular. However, we can start with VueJS coding
anywhere in jsfiddle or codepen using the cdn library. We can work with standard
JavaScript, which is very easy to start with.
Similarities
Ember provides Ember command line tool, i.e. ember-cli for easy installation and
compiling for Ember projects. VueJS has also a command line tool vue-cli to start
and build projects. They both have features such as router, template, and
components which makes them very rich as the UI framework.
Performance
VueJSv/s Knockout
Polymer library has been developed by Google. It is used in many Google projects
such as Google I/O, Google Earth, Google Play Music, etc. It offers data binding
and computed properties similar to VueJS. Polymer custom element definition
comprises plain JavaScript/CSS, element properties, lifecycle callbacks, and
JavaScript methods. In comparison, VueJS allows to easily use JavaScript/html
and CSS. Polymer uses web component features and requires polyfills for
browsers, which does not support these features. VueJS does not have such
dependencies and works fine in all browsers from IE9+.
CHAPTER 3
VUEJS-ENVIRONMENT SETUP
There are many ways to install VueJS. Some of the ways on how to carry out the
installation are discussed ahead.
<html>
<head>
</head>
<body>
</body>
</html>
We can also start using VueJS file from the CDN library. The link
https://unpkg.com/vue will give the latest version of VueJS. VueJS is also
available on jsDelivr (https://cdn.jsdelivr.net/npm/vue/dist/vue.js) and cdnjs
(https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.0/vue.js). We can host the files at
our end, if required and get started with VueJS development.
Using NPM
For large scale applications with VueJS, it is recommended to install using the
npm package. It comes with Browserify and Webpack along with other necessary
tools, which help with the development. Following is the command to install using
npm.
VueJS also provides CLI to install the vue and get started with the server
activation. To install using CLI, we need to have CLI installed which is done using
the following command.
Once done, it shows the CLI version for VueJS. It takes a few minutes for the
installation. + [email protected] added 965 packages in 355.414s Following is the
command to create the project using Webpack. vue init webpack myproject
CHAPTER 4
VUEJS INTRODUCTION
Vue is a JavaScript framework for building user interfaces. Its core part is focused
mainly on the view layer and it is very easy to understand. The version of Vue that
we are going to use in this tutorial is 2.0. As Vue is basically built for frontend
development, we are going to deal with lot of HTML, JavaScript and CSS files in
the upcoming chapters. To understand the details, let us start with a simple
example. In this example, we are going to use the development verison of vuejs.
EXAMPLE
In the above code snippet, we are calling Vue instance, which takes the id of the
DOM element i.e. e1:’#intro’, it is the id of the div. There is data with the message
which is assigned the value ‘My first VueJS Task’. VueJS interacts with DOM and
changes the value in the DOM {{message}} with ’My first VueJS Task’..
4.1 OUTPUT
This is the first app we have created using VueJS. As seen in the above code, we
have included vue.js at the start of the .html file.
There is a div which is added in the body that prints “My first VueJS Task” in the
browser.
<h1>{{message}}</h1>
</div>
We have also added a message in a interpolation, i.e. {{}}. This interacts with
VueJS and prints the data in the browser. To get the value of the message in the
DOM, we are creating an instance of vuejs as follows:
el: '#intro',
data: {
})
CHAPTER 5
COMPUTED PROPERTIES
5.1 REMARKS
The main use-case difference for the data and computed properties of a Vue
instance is dependent on the potential state or probability of changing of the data.
When deciding what category a certain object should be, these questions might
help:
5.2 EXAMPLES
BASIC EXAMPLE:
5.2.1 Template
<div id = “example”>
</div>
5.2.3 Javascript
el: '#example',
data: {
a: 1
},
computed: {
// a computed getter
b: function () {
return this.a + 1
}}
5.2.3 result
a=1,b=2
console.log(vm.b) // -> 2
vm.a = 2
console.log(vm.b) // -> 3
You can data-bind to computed properties in templates just like a normal property.
Vue is aware that vm.b depends on vm.a, so it will update any bindings that
depends on vm.b when vm.a changes.
5.3.1 Template
<div id = “demo”>
{{fullName}}
el: '#demo',
data: {
firstName: 'Foo',
lastName: 'Bar',
})
})
})
el: '#demo',
data: {
firstName: 'Foo',
lastName: 'Bar'
},
computed: {
fullName: function () {
}).
<div id = “exxample”>
</div>
5.5.2 Javascript
el: '#example',
data: {
a: 1
},
computed: {
b: {
// getter
get: function () {
return this.a + 1
},
// setter
this.a = newValue - 1
5.5.3 You can now invoke either the getter or the setter:
console.log(vm.b) // -> 2
vm.b = 4 // (setter)
console.log(vm.b) // -> 4
console.log(vm.a) // -> 3
vm.b = 4 will invoke the setter, and set this.a to 3; by extension, vm.b will evaluate
to 4.
You might need a v-model on a computed property. Normally, the v-model won't
update the computed property value.
The template:
<div id=”demo”>
</div>
<div class=’margin-5’>
offline to others)
</div>
</div>
5.7 STYLING
#demo{
font-family: Helvetica;
font-size: 12px;
.inline-block > * {
display: inline-block;
.card {
background: #ddd;
padding:2px 10px;
border-radius: 3px;
.onlineMarker {
width: 10px;
height: 10px;
border-radius: 50%;
.online {
background-color: #3C3;
.offline {
background-color: #aaa;
.user-state {
text-transform: uppercase;
letter-spacing: 1px;
.margin-5 {
margin: 5px;
el: '#demo',
data: {
statusProxy: null
},
computed: {
status: {
get () {
})
fiddle Here you would see, clicking the radio button has no use at all, your
status is still online.
el: '#demo',
data: {
statusProxy: null
},
computed: {
status: {
get () {
},
set (val) {
this.statusProxy = val
})
CHAPTER 6
CONDITIONAL RENDERING
6.1 REMARKS
It is very important to remember the difference between v-if and v-show. While
their uses are almost identical, an element bound to v-if will only render into the
DOM when it's condition is true for the first time. When using the v-show
directive, all elements are rendered into the DOM but are hidden using the display
style if the condition is false!
EXAMPLES
v-if
Element displays normally when condition is true. When the condition is false,
only partial compilation occurs and the element isn't rendered into the DOM until
the condition becomes true.
v-else
Does not accept a condition, but rather renders the element if the previous
element's v-if condition is false. Can only be used after an element with the v-if
directive.
v-show
Behaves similarly to v-if, however, the element will always be rendered into the
DOM, even when the condition is false. If the condition is false, this directive will
simply set the element's display style to none.
v-if / v-else
el: '#example',
data:{
a: true,
b: false
});
You can conditionally render any html element by including the v-if directive; the
element that contains v-if will only render if the condition evaluates to true:
<! will render ‘the condition is true’ into the DOM - - >
<div id = “example”>
</div>
The <h1> element will render in this case, because the variable 'a' is true. v-if can
be used with any expression, computed property, or function that evaluates to a
boolean:
You can use a template element to group multiple elements together for a single
condition:
< !-- In this case:nothing will be rendered expect for the containing ‘div’ - ->
<div id == “example”>
<h1>heading</h1>
<p>paragraph 1</p>
<p>paragraph 2</p>
</template>
</div>
When using v-if, you also have the option of integrating a counter condition with
the v-else directive. The content contained inside the element will only be
displayed if the condition of the previous v-if was false. Note that this means that
an element with v-else must appear immediately after an element with v-if.
<div id =”example”>
<h2>v-if = “a”>ELSE</h1>
</div>
Just as with v-if, with v-else you can group multiple html elements together within
a <template>:
<template v-else>
<ul>
<li>will be rendered</li>
</ul>
</template>
6.2 V-SHOW
The use of the v-show directive is almost identical to that of v-if.The only
difference are that v-show does not support the <template> syntax, and there is no
"alternative" condition.
el: '#example',
data: {
a: true
});
<div id =”example”>
</div>
While v-show does not support the v-else directive to define "alternative"
conditions, this can be accomplished by negating the previous one...
<div id = “example”>
</div>
CHAPTER 7
7.1 INTRODUCTION
Having individual stores for each component each time they get used gets
complicated.
7.1.1 Remarks
<componenet
:value=”something”
@input=”something=$event.target.value”
>
</component>
EXAMPLES
// child component
Vue.component('counter', {
<button @click=’sub’>-1</button>
data () {
return {
result: 0
},
props: ['value'],
methods: {
emitResult () {
this.$emit('input', this.result)
},
add () {
this.result +=
1 this.emitResult()
},
sub () {
this.result -= 1
this.emitResult()
})
This child component will be emitting result each time sub() or add() methods are
called.
// parent component
new Vue ( {
el:’#demo’,
data () {
return {
resultFromChild:null
}
})
This child component will be emitting result each time sub() or add() methods are
called.
//parent template
<div id =’demo’>
<counter V-model=’ResultFromChild’></counter>
</div>
Since v-model is present on the child component, a prop with name value was sent
at the same time, there is an input event on the counter which will in turn provide
the value from the child component
CHAPTER 8
CUSTOM DIRECTIVES
8.1 BASICS
In addition to the default set of directives shipped in core, Vue.js also allows you
to register custom directives. Custom directives provide a mechanism for mapping
data changes to arbitrary DOM behavior. You can register a global custom
directive with the Vue.directive(id, definition) method, passing in a directive id
followed by a definition object. You can also register a local custom directive by
including it in a component’s directives option.
• bind: called only once, when the directive is first bound to the element.
• update: called for the first time immediately after bind with the initial value, then
again whenever the binding value changes. The new value and the previous value
are provided as the argument.
• unbind: called only once, when the directive is unbound from the element.
Vue.directive('my-directive', {
bind: function () {
// do preparation work
},
unbind: function () {
// do clean up work
})
Once registered, you can use it in Vue.js templates like this (remember to add
the v- prefix):
When you only need the update function, you can pass in a single function
instead of the definition object:
})
All the hook functions will be copied into the actual directive object, which you
can access inside these functions as their this context. The directive object exposes
some useful properties:
• descriptor: an object that contains the parsing result of the entire directive.
You should treat all these properties as read-only and never modify them. You can
attach custom properties to the directive object too, but be careful not to
accidentally overwrite existing internal ones.
HTML
JAVASCRIPT
Vue.directive('demo', {
bind: function () {
console.log('demo bound!')
},
this.el.innerHTML =
})
el: '#
data: {
msg: 'hello!'
})
RESULT
name - demo
expression - msg
argument - hello
modifiers - {"b":true,"a":true}
value - hello!
If your directive needs multiple values, you can also pass in a JavaScript object
literal. Remember, directives can take any valid JavaScript expression:
HTML
JAVASCRIPT
console.log(value.color) // "white"
console.log(value.text) // "hello!"
})
When a directive is used with the literal modifier, its attribute value will be
interpreted as a plain string and passed directly into the update method. The update
method will also be called only once, because a plain string cannot be reactive.
HTML
JAVASCRIPT
})
CHAPTER 9
CUSTOM FILTERS
With a two-way filter, we are able to assign a read and write operation for a single
filter that changes the value of the same data between the view and model.
//JS
Vue.filter('uppercase', {
read: function(value) {
return value.toUpperCase();
},
write: function(value) {
return value.toLowerCase();
});
/*
*/
9.2 BASICS
//JS
Vue.filter('reverse', function(value) {
return value.split('').reverse().join('');
});
//HTML
It is good practice to store all custom filters in separate files e.g. under ./filters
as it is then easy to re-use your code in your next application. If you go this
way you have to replace JS part:
//JS
Vue.filter('reverse', require('./filters/reverse'));
You can also define your own begin and end wrappers as well.
});
//HTML
{{ msg | wrap 'The' 'fox' }} //'quick brown' => 'The quick brown fox'
9.3 SYNTAX
CHAPTER 10
10.1.1 Text
The most basic form of data binding is text interpolation using the “Mustache”
syntax (double curly braces):
The mustache tag will be replaced with the value of the msg property on the
corresponding data object. It will also be updated whenever the data object’s msg
property changes.
You can also perform one-time interpolations that do not update on data change:
This will never change:
The double mustaches interpret’s the data as plain text, not HTML. In order to
output real HTML, you will need to use triple mustaches:
The contents are inserted as plain HTML - data bindings are ignored. If you need
to reuse template pieces, you should use partials.
10.1.3 Attributes
Note that attribute interpolations are disallowed in Vue.js directives and special
attributes. Don’t worry, Vue.js will raise warnings for you when mustaches are
used in wrong places.
10.1.4 Filters
Vue.js allows you to append optional “filters” to the end of an expression, denoted
by the “pipe” symbol:
{{ message | capitalize }}
Here we are “piping” the value of the message expression through the built-in
capitalize filter, which is in fact just a JavaScript function that returns the
capitalized value. Vue.js provides a number of built-in filters, and we will talk
about how to write your own filters later.
Note that the pipe syntax is not part of JavaScript syntax, therefore you cannot mix
filters inside expressions; you can only append them at the end of an expression.
The filter function always receives the expression’s value as the first argument.
Quoted arguments are interpreted as plain string, while un-quoted ones will be
evaluated as expressions. Here, the plain string 'arg1' will be passed into the filter
as the second argument, and the value of expression arg2 will be evaluated and
passed in as the third argument.
Dynamically switch between multiple components using element and pass data to
vbind:is attribute:
JAVASCRIPT
new Vue({
el: '#app',
data: {
currentPage: 'home'
},
components: {
home: {
template: “<p>Home</p>”
},
about: {
template : ”<p>About</p>”
},
contact: {
template : ”<p>Contact</p>”
})
HTML :
<div id=”app”>
</component>
</div>
Sometimes you want to keep the switched-out components in memory, to make that
happen, you should use element:
JAVASCRIPT
new Vue({
el: '#app',
data: {
currentPage: 'home',
},
methods: {
switchTo: function(page) {
this.currentPage = page;
},
components: {
home: {
template : ‘<div>
<h2>Home</h2>
</div>’,
data: function() {
return {
},
about: {
template : ‘<div>
<h2>about</h2>
</div>’,
data: function() {
return {
},
contact: {
template : ‘<div>
<h2>form</h2>
<label>your message</label>
<button type=”submit”>send</button>
</form>
</div>’,
data : function() {
return {
})
CHAPTER 11
CONCLUSIONS
Vue.js is a Progressive JavaScript Framework for building web apps and it doesn’t
load itself in the browser. We need some kind of mechanism that loads the
index.html (single page) of Vue application with all the dependencies (CSS and js
files) in the browser.
Vue (pronounced /vjuː/, like view) is a progressive framework for building user
interfaces. Unlike other monolithic frameworks, Vue is designed from the ground
up to be incrementally adoptable. The core library is focused on the view layer
only, and is easy to pick up and integrate with other libraries or existing projects.
REFERENCES
[1] https://vuejs.org
[2] https://vuejs.org/v2/guide
[3] https://riptutorial.com
[4] https://v3.vuejs.org/api/refs-api.html