利用VUE实现TODOLIST
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TODOLIST</title>
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css" href="./bootstrap-3.3.7-dist/css/bootstrap.min.css">
<script type="text/javascript" src="./vue/vue.js"></script>
</head>
<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>
结果展示:
---------------------------------------
本文转自qushen1212博客51CTO博客
如需转载,请联系作者授权
原文链接:http://blog.51cto.com/13507330/2097102
- 点赞
- 收藏
- 关注作者
评论(0)