Vue JS To Do
Vue equivalent of this React To Do
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.1/vue.js Copy"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.1/vue.js"></script>
<div id="container">
<ul>
<item
v-for="(value, index) in items"
:number="index + 1"
:text="value">
</item>
</ul>
<input type="text" v-model="input" @keyup.enter="onSubmit">
</div>
<template id="item-template">
<li>{{ number }} - {{ text }}</li>
</template>
JavaScript
Vue.component('item', {
'template':'#item-template',
'props':['number', 'text']
})
var app = new Vue({
el:'#container',
data:{
input:'',
items:[]
},
created:function()
{
this.items = [
'Buy ingredients for Crock Pot',
'Pick up chair at IKEA',
'Go see mom'
]
},
methods:
{
onSubmit:function()
{
this.items.push(this.input);
this.input = '';
}
}
})