利用VUE實現TODOLIST
阿新 • • 發佈:2018-04-11
VUE TODOLIST Bootstrap <!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> <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>
<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">
<script type="text/javascript" src="./vue/vue.js"></script>
</head>
<body>
<div class="container" id="ap">
<div class="row" >
<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"/>
<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