Framework | Rozmiar zminifikowanej paczki produkcyjnej |
---|---|
React 16.2.0 + React DOM | 97.5K |
Angular 2 | 566K |
Vue 2.4.2 | 58.8K |
{{ message }}
new Vue({
el: '#app',
data: {
message: 'Hello Vue.js!'
}
})
{{ message }}
new Vue({
el: '#bind',
data: {
link: 'http://agh.edu.pl'
}
})
new Vue({
el: '#bind-events',
data: {
message: 'To zostanie wyświetlone jako alert'
},
methods: {
showAlert: function () {
alert(this.message);
}
}
})
new Vue({
el: '#cond',
data: {
message: 'Widać mnie?',
show: false
},
methods: {
showMsg: function () {
this.show = !this.show;
}
}
})
{{ option }}
new Vue({
el: '#loop',
data: {
options: ['Pizza', 'Kebab', 'Sushi', 'Bibimbap']
},
methods: {
pickFood: function (option) {
alert('Jemy: ' + option);
}
}
})
Moja nazwa dania: {{ meal }}
new Vue({
el: '#model',
data: {
meal: ''
}
})
Moja nazwa dania: {{ meal }}
Vue.component('resto', {
props: ['place'],
template: '{{ place.text }} '
})
new Vue({
el: '#components',
data: {
places: [
{ id: 0, text: 'Kebab' },
{ id: 1, text: 'Pizza' },
{ id: 2, text: 'Sushi' }
]
}
})
const br1 = new Vue({
el: '#breaker1',
computed: {
now: function() {
return Date.now()
}
},
methods: {
realNow: function() {
return Date.now()
}
}
})
Teraz jest: {{ now }}
const br2 = new Vue({
el: '#breaker2',
data: {
user1: {
name: 'SRiR'
},
user2: {
name: 'ZTI'
}
}
});
br2.admin = { name: 'DDay', passwd: '123456' };
br2.user1.passwd = '141592';
Vue.set(br2.user2, 'passwd', '141592');
{{ user1.passwd }} | ||
{{ user2.passwd }} | ||
{{ admin.passwd }} |
addSushi: function() {
this.options.push({ name: 'suszi', from: 'Japan' })
},
correctSushi: function() {
this.options[1].name = 'sushi'
},
maybeBibimbap: function() {
this.options[1] = { name: 'bimbap', from: 'Korea' }
},
readdBibimbap: function() {
Vue.set(this.options, 1, { name: 'bimbap', from: 'Korea' })
},
correctBibimbap: function() {
this.options[1].name = 'bibimbap'
}
Restauracje
Jedzenie
const Resto = { template: 'Resto' }
const Food = { template: 'Food' }
const routes = [
{ path: '/resto', component: Resto },
{ path: '/food', component: Food }
]
const router = new VueRouter({
routes
})
const app = new Vue({
router
}).$mount('#app-router')
State Management Pattern
const store = new Vuex.Store({
state: {
name: ''
},
mutations: {
setName (state, name) {
state.name = name;
}
}
})
https://vuex.vuejs.org/
Generator stron statycznych
https://vuepress.vuejs.org/Korzystając z API, zaprojektuj SPA z wewnętrznym routingiem