利用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>
結果展示:
利用VUE實現TODOLIST

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章