The Progressive JavaScript Framework
Estudiante de ing. sistemas && Desarrollador && Profesor
|| @maranimatias
Creado por Evan You, cuando estaba trabajando en Google Creative Labs.
Evan You:
"I figured, what if I could just extract the part that I really liked about Angular and bulid something really lightweight without all the extra concepts involved?"
Comparando con Angular.JS - El original.
Comparando con React.
Comparando con Angular.
Progresivo.
Renderizado declarativo.
Reactivo.
Componente functional.
<script src="https://unpkg.com/vue"></script>
<body>
{{ message }}
<body>
Un Componente Vue
Vue.component('hello-component', {
template: '#hello',
data: function () {
return {
message: 'Welcome to your Vue.js app!'
}
}
});
{{ message }}
<body>
</body>
Methods
{{ message }}
Vue.component('hello-component', {
template: '#hello',
data: function () {
return { message: 'Welcome to your Vue.js app!' }
},
methods: {
change: function(value) {
this.message = "new " + value;
}
}
});
Eventos
Eventos para teclas
Do something
El evento submit no recargara la pagina.
computed
Original message: "{{ message }}"
Computed reversed message: "{{ reversedMessage }}"
Vue.component('hello-component', {
template: '#hello',
data: function () {
return { message: 'Welcome to your Vue.js app!' }
},
methods: { /* ... */ },
computed: {
reversedMessage: function () {
return this.message.split('').reverse().join('')
}
}
});
Usar los eventos en nuestro componente
Vue.component('hello-component', {
template: '#hello',
data: function () {
return { message: 'Welcome to your Vue.js app!' }
},
methods: { /* ... */ },
computed: { /* ... */ },
beforeCreate: function(){ /* ... */ },
created: function(){ /* ... */ },
beforeMount: function(){ /* ... */ },
mounted: function(){ /* ... */ }
beforeUpdate: function(){ /* ... */ },
updated: function(){ /* ... */ }
});
Directivas de control de flujo
Mayor
<p v-else> Menor </p>
Math.random() Mayor que 0.5
-
{{ item.message }}
-
{{ parentMessage +" - "+ index +" - "+ item.message }}
{{ key + ": " + value }}
atributos vinculados HTML
o sintaxis abreviada :
Directivas personalizadas
<input v-focus>
// Register a global custom directive called v-focus
Vue.directive('focus', {
inserted: function (el) {
el.focus();
}
})
Podemos declara directivas locales para cada componente.
Filtros
{{ message | capitalize }}
Vue.filter('capitalize', function (value) {
if (!value) return '';
value = value.toString();
return value.charAt(0).toUpperCase() + value.slice(1);
});
Comunicación entre padres e hijos.
Eventos Personalizados
Vue.component('parent', {
template: '#parent',
data: function () { return { count: 0 } },
methods: {
mParent: function (value) { this.count += value; }
}
});
Vue.component('child', {
props: ['clicks'],
template: '',
methods: {
mChild: function () { this.$emit('count', 5); }
}
});
Comunicación entre componentes sin parentesco
var bus = new Vue()
// in component A's method
bus.$emit('id-selected', 1)
// in component B's created hook
bus.$on('id-selected', function (id) {
// ...
})
Slots
el título de padre
Titulo
Se mostrará dentro de Slot
el título del hijo
Esto sólo se mostrará si no hay contenido
$ # install vue-cli
$ npm install --global vue-cli
$ vue init webpack my-project
$ cd my-project
$ npm install
$ npm run dev
var Vuex = require('vuex');
Vue.use(Vuex);
The Majesty of Vue.js 2
Learning Vue.js 2
Gracias