π
Paul Melero
Web Developer
Github | gangsthub |
---|---|
@paul_melero | |
CodeSandBox | gangsthub/sandboxes |
Web | graficos.net |
Agriculture Eng. π΅
We have better performance.
Gregg Pollack (Vue Mastery) and Evan You (Creator)
Not mandatory API, tho
Β
*html
*js/*ts
*(s)css
Image from docs
<div id="simplest-example">
<h1>{{ whatever }}</h1>
</div>
new Vue({
Β el: '#simplest-example',
Β data: {
Β Β whatever: 'Hello world',
Β }
})
1
2
3
...
1
2
3
4
5
npm install --global @vue/cli
Β
>
<div id="app">
<span
v-if="seen"
>Now you see me</span>
</div>
new Vue({
el: '#app',
data: () => ({
seen: true // <----
})
});
v-if
<div id="app">
<ol>
<li v-for="todo in todos">
{{ todo.text }}
</li>
</ol>
</div>
new Vue({
el: '#app',
data: () => ({
todos: [ // <----
{ text: 'Learn JavaScript' },
{ text: 'Learn Vue' },
{ text: 'Build something awesome' }
]
})
})
Loopsβ
v-for (in)
<!-- method handler -->
<button v-on:click="doThis"></button>
<!-- same as -->
<button v-on:click="doThis($event)"></button>
<!-- shorthand -->
<button @click="doThis"></button>
<!-- key modifier using keyAlias -->
<input @keyup.enter="onEnter">
new Vue({
el: '#app',
// data: {},
methods: { // <----
doThis: function(...args) { /* ... */ }
}
})
<div id="app">
<p>{{ message }}</p>
<input v-model="message">
</div>
new Vue({
el: '#app',
data() {
return {
message: 'How vuetiful is that!'
}
}
})
<div id="app">
<p>{{ message }}</p>
<p>{{ message.split('').reverse().join('') }}</p>
</div>
new Vue({
el: '#app',
data: {
message: 'I\'m the original message'
},
})
<p>{{ reversedMessage }}</p>
computed: {
reversedMessage: function () {
return this.message.split('').reverse().join('')
}
}
computed: {
reversedMessage() {
return this.message.split('').reverse().join('')
}
}
new Vue({
el: '#app',
beforeCreate() {},
created() {},
beforeMount() {},
mounted() {},
beforeUpdate() {},
updated() {},
activated() {},
deactivated() {},
beforeDestroy() {},
destroyed() {},
errorCaptured() {},
})
Global vs Local
<template>
<form @submit="handleSubmit">
<SearchBox />
</form>
</template>
<script lang="ts">
import SearchBox from '@/components/SearchBox'
export default {
components: {
SearchBox
},
methods: {
handleSubmit() { /*...*/ }
}
}
</script>
π
<template>
<form>
<SearchBox :something="myValue" />
</form>
</template>
<script lang="ts">
import SearchBox from '@/components/SearchBox'
export default {
components: {
SearchBox
},
data() {
return {
myValue: 42
}
},
}
</script>
<template>
<div>
Search box component
{{ something }}
<!-- TODO: implement searchbox -->
</div>
</template>
<script lang="ts">
export default {
props: {
something: {
type: [Number, String],
required: true
},
otherThingHere: {
type: String,
default: 'Hi',
},
someMoreConfiguration: {
type: Object,
default: () => ({})
}
},
}
</script>
new Vue({
el: '#app',
components: {
Child: {
template: `<button @click="$emit('myEvent', 1)">`
}
},
methods: {
onMyEvent(value) { console.log(value) },
},
template: `
<Child @myEvent="onMyEvent">
`,
})
Child
App
"myEvent"
1
click