Vue 2.0 Hello World
by Daniel Newman
HTML
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="app">
<p v-once>
{{message}}
</p>
<p>{{ message | capitalize }}</p>
<ol>
<todo-item v-for="listitem in todos" v-bind:todo="listitem"></todo-item>
</ol>
<input v-model="message"/>
<button :title="'Click to Do'" @click="reverseMessage">click me</button>
</div>
JavaScript
Vue.component('todo-item', {
props: ['todo'],
template: '<li>{{ todo.text }}</li>'
})
var myApp =new Vue({
el: '#app',
data: {
message: 'daniel newman',
seen: false,
todos: [{text: 'dan'},{text:'newman'},{text: 'isgreat'}]
},
methods: {
reverseMessage: function () {
this.message = this.message.split('').reverse().join('')
}
},
watch: {
message: function(newVal){
for (var t in this.todos) if (this.todos[t].text === newVal) return;
this.todos.push({text: newVal})
}
},
filters: {
capitalize: function (value) {
if (!value) return ''
value = value.toString()
return value.charAt(0).toUpperCase() + value.slice(1)
}
}
})