<body>
<div class="container" id="ap">
<div class="row" >
<div class="col-md-6 col-md-offset-3">
<h1 class="text-info text-center" >{{ title }}</h1>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4">
请输入:<input type="text" name="text" placeholder="请输入备忘事件" v-model="newItem"/>
<button type="button" class="btn btn-info" v-on:click="add">提交</button>
<p>内容:</p>
<div class="thumbnail">
<ul>
<li v-for="(item,index) in items" class="text-center text-info" >{{item.label}}<button class="btn btn-default bg-info" v-on:click="remove(index)" v-model="index">取消</button></li>
</ul>
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
var vue=new Vue({
el:‘#ap‘,
data:{
title:‘备忘录‘,
items:[],
newItem:‘‘,
message:‘不能输入空字符串!‘
},
methods:{
add:function(){
if(this.newItem){
this.items.splice(0,0,{label:this.newItem});
this.newItem=‘‘
}else{
alert(this.message)
}
},
remove:function(index){
this.items.splice(index,1)
}
}
});
</script>
</html>
结果展示:
原文地址:http://blog.51cto.com/13507330/2097102