Académique Documents
Professionnel Documents
Culture Documents
John Papa
Developer Advocate
@john_papa
Vue from 20,000 Feet:
Fundamentals and Best Practices
John Papa
Developer Advocate
@john_papa
Resources
VS Code https://aka.ms/psv-code
@john_papa
Real Developer Stories Every Week
http://realtalkjs.com
@john_papa
Vue
@john_papa
Vue
@john_papa
Vue
@john_papa
Easy
Running in minutes
Learn a ton in a week
Seriously!
@john_papa
index.html
Make Progress Quickly <html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vu
e"></script>
Drop a script tag </head>
<body>
Set a data value <div id="app">
<input type="text" v-model="name" />
<p>Hello {{ name }}</p>
</div>
<script>
new Vue({
el: '#app’,
data() {
return { name: 'John’ };
}
});
</script>
</body>
</html>
@john_papa
What Makes Starting a New App Difficult?
@john_papa
Vue CLI
Built-in Features
Stylus PWA
Linting Nightwatch
Webpack Babel
Jest
Cypress.io
Modern mode
Mocha Sass
Less
TypeScript Web components
@john_papa
The Vue CLI makes it easy to
create an application that
works and follows best
practices,
right out of the box.
@john_papa
Installing Node.js and the Vue CLI
Go to https://nodejs.org
LTS represents
Long Term Support
Download and install the LTS version for your Operating System
@john_papa
Vue CLI’s Main Commands
@john_papa
Vue CLI UI
@john_papa
@john_papa
heroes.vue
data() {
The data() function identifies the
return { data models
name: "John"
};
};
</script>
header-bar-links.vue
</a>
Property Binding
Bind to an HTML property
Two-way Binding
The hero.firstName is shown in the input
The user types and the value of hero.firstName changes
heroes.vue
<div class="field">
</div>
Two-way binding
Vue has several shortcuts
for template syntax
@john_papa
heroes.vue
</li>
</ul>
Render a List
Iterate over a list of items in a model with v-for="item in item-list"
Repeats the HTML content for each item in the list
Bind to a unique :key, for faster rendering
Indexing Loops
@john_papa
Conditionals
Display content based on an expression
Content is added or removed from the DOM
Set the v-if directive to an expression that evaluates to truthy or falsey
heroes.vue
Add the content to the DOM if
there is a selectedHero
<div v-if="selectedHero">
</div>
heroes.vue
Event Bindings <template>
<div>
Execute when an event occurs
<input v-model="name" type="text">
</div>
</template>
@ is the shortcut syntax
for v-on <script>
export default {
methods: {
ok() { /* do something */ }
};
</script>
heroes.vue
<option>Speed</option>
Class Bindings
Class binding syntax :class="{classname: expression}"
Object literal
Class on the left
Expression on the right
Template Syntax
v-for Loop
@john_papa
@john_papa
Life Cycle Hooks
beforeCreate created
beforeMount mounted
beforeUpdate updated
beforeDestroy destroyed
https://vuejs.org/v2/guide/instance.html#Instance-Lifecycle-Hooks
@john_papa
Computed Properties
Watchers
@john_papa
Computed Properties
Fire when any dependency value changes
Cached based on its reactive dependencies
Only re-evaluates when any of its reactive dependencies have
changed
heroes.vue
When either dependency
changes, the computed
computed: { evaluates
fullName() {
},
},
heroes.vue
Watchers
React when this model changes
},
When both work,
computed are often a
better choice
@john_papa
Component Organization
Heroes
HeroListItem CustomButton
heroes.vue
We pass values from parent to a
child, using bindings and props
v-if="selectedHero" props: {
:hero="selectedHero" hero: {
/> type: Object,
default: () => {},
},
},
}
Component Communication - In
Props
Pass values in
@john_papa
Component Communication - Out
@john_papa
Rich Ecosystem
Vuex https://vuex.vuejs.org/en/
UX https://vuetifyjs.com
Debugging https://vuejs.org/v2/cookbook/debugging-in-vscode.html
@john_papa
Resources
VS Code https://aka.ms/psv-code
@john_papa
You can successfully build
powerful apps with Vue
John Papa
Developer Advocate
@john_papa