VUE.JS th e progressiv e javascrip t framewor k VUE.JS "Vue is - - PowerPoint PPT Presentation

vue js
SMART_READER_LITE
LIVE PREVIEW

VUE.JS th e progressiv e javascrip t framewor k VUE.JS "Vue is - - PowerPoint PPT Presentation

CS498RK SPRING 2020 VUE.JS th e progressiv e javascrip t framewor k VUE.JS "Vue is a progressive framework for building user interfaces. Unlike other monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable.


slide-1
SLIDE 1

SPRING 2020 CS498RK

VUE.JS

the progressive javascript framework

slide-2
SLIDE 2

VUE.JS

"Vue 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 Single-Page Applications when used in combination with modern tooling and supporting libraries."

https://vuejs.org/v2/guide/

slide-3
SLIDE 3

DECLARATIVE RENDERING

var app = new Vue({ el: '#app', data: function () { return { message: 'Hello Vue!', title: 'You loaded this page on ' + new Date().toLocaleString() } } }) <div id="app"> <p> {{ message }} </p> <p> <span v-bind:title="title"> Hover over to see dynamic title </span> </p> </div>

CodePen

https://vuejs.org/v2/guide/

text interpolation directive

slide-4
SLIDE 4

CONDITIONALS AND LOOPS

var app = new Vue({ el: '#app', data: function () { return { show: true, items: [ { text: 'Foo' }, { text: 'Bar' }, { text: 'Baz' } ] } }, methods: { toggle() { this.show = !this.show } } }) <div id="app"> <div> <span v-if="show">Hello there!</span> <button v-on:click="toggle"> Toggle </button> </div> <ol> <li v-for="item in items"> {{ item.text }} </li> </ol> </div>

CodePen

https://vuejs.org/v2/guide/

v- directives

slide-5
SLIDE 5

HANDLING USER INPUT

https://vuejs.org/v2/guide/

var app = new Vue({ el: '#app', data: function () { return { text: 'Do you wanna see a magic trick?', button: 'Magic!' } }, methods: { magic() { this.text = this.text.split('').reverse().join('') this.button = this.button.split('').reverse().join('') } } }) <div id="app"> <div> <p>{{ text }}</p> <button v-on:click="magic">{{ button }}</button> </div> <div> <input v-model="text"> </div> </div>

CodePen

slide-6
SLIDE 6

COMPOSITION

var app = new Vue({ el: '#app', data: function () { return { todos: [ { id: 0, text: 'Work it' }, { id: 1, text: 'Make it' }, { id: 2, text: 'Do it' } ] } } }) Vue.component('todo-item', { props: ['todo'], template: '<li>{{ todo.text }}</li>' })

CodePen

https://vuejs.org/v2/guide/ <div id="app"> <ol> <todo-item v-for="item in todos" v-bind:todo="item" v-bind:key="item.id" ></todo-item> </ol> </div >

slide-7
SLIDE 7

TEMPLATE SYNTAX

Text

<span>Message: {{ msg }}</span> <span v-html="rawHtml"></span> <div v-bind:id="myId"></div> {{ ok ? 'YES' : 'NO' }} <p v-if="show">show is True</p>

Raw HTML Attributes Directives Expressions

slide-8
SLIDE 8

SHORTHANDS

<!-- full syntax --> <a v-on:click="doSomething"> ... </a> <!-- shorthand --> <a @click="doSomething"> ... </a> <!-- full syntax --> <a v-bind:href="url"> ... </a> <!-- shorthand --> <a :href="url"> ... </a>

v-bind v-on

use : use @

slide-9
SLIDE 9

beforeCreate() beforeMount() created()

runs at the very initialization of your component. data has not been made reactive, and events have not been set up yet.

mounted() beforeUpdate() updated() beforeDestroy() destroyed()

you will be able to access reactive data and events are active. Templates and Virtual DOM have not yet been mounted or rendered. runs right before the initial render happens and after the template or render functions have been compiled you will have full access to the reactive component, templates, and rendered DOM (via. this. $el) runs after data changes on your component and the update cycle begins, right before the DOM is patched and re-rendered. runs after data changes on your component and the DOM re-renders fired right before teardown there’s pretty much nothing left on your component

https://alligator.io/vuejs/component-lifecycle/

slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12

COMPUTED PROPERTIES

<div id="example"> <p>Original message: "{{ message }}"</p> <p>Computed reversed message: "{{ reversedMessage }}"</p> </div> var vm = new Vue({ el: '#example', data: { message: 'Hello' }, computed: { // a computed getter reversedMessage: function () { // `this` points to the vm instance return this.message.split('').reverse().join('') } } })

slide-13
SLIDE 13

PASSING DATA

Child Parent

Use Props! Use $emit OR Pass Handlers as Props (Like React)

slide-14
SLIDE 14

SLOTS

<alert-box> Something bad happened. </alert-box>

Vue.component('alert-box', { template: ` <div class="demo-alert-box"> <strong>Error!</strong> <slot></slot> </div> ` })

slide-15
SLIDE 15

demo

https://gitlab.com/uiuc-web- programming/vue-demo

slide-16
SLIDE 16

RESOURCES

Vue.js Guide https://vuejs.org/v2/guide/ Vue CLI https://cli.vuejs.org/

slide-17
SLIDE 17

NEXT CLASS: GUEST LECTURE: SCALING WITH AWS

https://uiuc-web-programming.gitlab.io/sp20/