Martin Janyš
{
el: '#app',
data: {},
methods: {}
}
<div id="app">
<app-nav></app-nav>
<app-view>
<app-sidebar></app-sidebar>
<app-content></app-content>
</app-view>
</div>
{{ number + 1 }}
{{ ok ? 'YES' : 'NO' }}
{{ message.split('').reverse().join('') }}
{{ message | capitalize }}
{{ message | filterA | filterB }}
{{ message | filterA 'arg1' arg2 }}
<span>Message: {{ msg }}</span>
<span>This will never change: {{* msg }}</span>
<div>{{{ raw_html }}}</div>
<div id="item-{{ id }}"></div>
attributes with the v- prefix
<a v-bind:href="url"></a>
<a v-bind:href="url"></a>
<a v-on:click="doSomething">
<a v-bind:href.literal="/a/b/c"></a>
<!-- full syntax -->
<a v-bind:href="url"></a>
<!-- shorthand -->
<a :href="url"></a>
or
<!-- full syntax -->
<button v-bind:disabled="someDynamicCondition">
Button
</button>
<!-- shorthand -->
<button :disabled="someDynamicCondition">
Button
</button>
<!-- full syntax -->
<a v-on:click="doSomething"></a>
<!-- shorthand -->
<a @click="doSomething"></a>
// ...
computed: {
fullName: {
// getter
get: function () {
return this.firstName + ' ' + this.lastName
},
// setter
set: function (newValue) {
var names = newValue.split(' ')
this.firstName = names[0]
this.lastName = names[names.length - 1]
}
}
}
// ...
<div class="static"
:class="{'class-a':isA, 'class-b':isB}">
</div>
<div v-bind:class="[classA, classB]">
data: {
isA: true,
isB: false
}
data: {
classA: 'class-a',
classB: 'class-b'
}
you can directly bind to an object in data as well
data: {
classes: ['class-a', 'class-b']
}
data: {
classes: {
'class-a': true,
'class-b': false
}
}
<div v-bind:style="styleObject"></div>
<div v-bind:style="[styleObjectA, styleObjectB]">
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
<!-- the click event's propagation will be stopped -->
<a v-on:click.stop="doThis"></a>
<!-- the submit event will no longer reload the page -->
<form v-on:submit.prevent="onSubmit"></form>
<!-- modifiers can be chained -->
<a v-on:click.stop.prevent="doThat">
<!-- just the modifier -->
<form v-on:submit.prevent></form>
<!-- only call vm.submit() when the keyCode is 13 -->
<input v-on:keyup.13="submit">
<!-- same as above -->
<input v-on:keyup.enter="submit">
<tr is="my-component"></tr>
Include by <link rel="import" href="">
<div>
<template id="myTemplate">
<!-- template -->
</template>
<style type="text/css" scoped>
<!-- css -->
</style>
<script type="text/javascript">
<!-- js -->
</script>
</div>
var data = { a: 1 }
var vm = new Vue({
data: data
})
// `vm.a` and `data.a` are now reactive
vm.b = 2
// `vm.b` is NOT reactive
data.b = 2
// `data.b` is NOT reactive
vm.$set('b', 2)
// `vm.b` and `data.b` are now reactive
Vue.set(data, 'c', 3)
// `vm.c` and `data.c` are now reactive
this.someObject = Object.assign({},
this.someObject,
{ a: 1, b: 2 })
var vm = new Vue({
template: '<div>{{msg}}</div>'
})
vm.$set('msg', 'Hello!')
var vm = new Vue({
data: {
msg: ''
},
template: '<div>{{msg}}</div>'
})
vm.msg = 'Hello!'
var App = Vue.extend({})
var router = new VueRouter()
router.map({
'/foo': {
component: Foo
},
'/bar': {
component: Bar
}
})
router.start(App, '#app')
/* HTTP Client */
this.$http({url: '/someUrl', method: 'GET'}).then(function (response) {
// success callback
}, function (response) {
// error callback
});
/* ROSOURCE */
var resource = this.$resource('someItem/{id}');
resource.get({id: 1}).then(function (response) {
this.$set('item', response.item)
});
resource.save({id: 1}, {item: this.item}).then(function (response) {
// success callback
}, function (response) {
// error callback
});
resource.delete({id: 1}).then(function (response) {
// success callback
}, function (response) {
// error callback
});
}
index.html structure