Vue:实现一个基本的项目todolist

Vue:实现一个基本的项目todolist

app.js代码:
(function(Vue){
	new Vue({
		el:'#todoapp',
		data:{
			title:'Todoapp',
			list:[]
		},
		methods:{
			add:function(ev){
				var input = ev.target;
				value=input.value.trim();
				if(value == ""){
					return;
				}
				data ={
					id:this.list.length+1,
					name:value,
					status:false,
					shows:true,
				}
				this.list.push(data);
				input.value = '';
			},
			
			selectAll:function(ev){
			  var input	= ev.target;
				for(let i=0;i<this.list.length;i++){
					this.list[i].status = input.checked;
				}
			},
			
			del:function(key){
				this.list.splice(key,1)
			},
			
			delCompleted:function(){
				this.list = this.list.filter((v)=> v.status == false)
			},
			
		}
	})
})(Vue)
index.html代码
<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>Template • TodoMVC</title>
		<link rel="stylesheet" href="node_modules/todomvc-common/base.css">
		<link rel="stylesheet" href="node_modules/todomvc-app-css/index.css">
		<!-- CSS overrides - remove if you don't need it -->
		<link rel="stylesheet" href="css/app.css">
	</head>
	<body >

		<section class="todoapp" id="todoapp">
			<header class="header">
				<h1>{{title}}</h1>
				<input class="new-todo" @keyup.enter="add($event)" placeholder="What needs to be done?" autofocus>
			</header>
			<div v-if="list.length">
			<!-- This section should be hidden by default and shown when there are todos -->
			<section class="main">
				<input id="toggle-all" @click="selectAll($event)" class="toggle-all" type="checkbox">
				<label for="toggle-all">选中全部</label>
				<ul class="todo-list">
					<!-- These are here just to show the structure of the list items -->
					<!-- List items should get the class `editing` when editing and `completed` when marked as completed -->
					<li v-for="(val,key) in list" v-if="val.shows"  v-bind:class="{completed:val.status}">
						<div class="view">
							<input class="toggle" type="checkbox" v-model="val.status">
							<label >{{val.name}}</label>
							<button @click="del(key)" class="destroy"></button>
						</div>
						<input class="edit" value="Create a TodoMVC template">
					</li>
				</ul>
			</section>
			<!-- This footer should be hidden by default and shown when there are todos -->
			<footer class="footer">
				<!-- This should be `0 items left` by default -->
				<span class="todo-count"><strong>{{list.length}}</strong> item left</span>
				<!-- Remove this if you don't implement routing -->
				<ul class="filters">
					<li>
						<a class="selected" href="#/" @click="all()" >All</a>
					</li>
					<li>
						<a href="#/active" @click="active()">Active</a>
					</li>
					<li>
						<a href="#/completed" @click="completed()" >Completed</a>
					</li>
				</ul>
				<!-- Hidden if no completed items are left ↓ -->
				<button @click="delCompleted()" class="clear-completed">Clear completed</button>
			</footer>
		</section>
		</div>
		<footer class="info">
			<p>双击修改</p>
			<!-- Remove the below line ↓ -->
			<p>Template by <a href="http://sindresorhus.com">Sindre Sorhus</a></p>
			<!-- Change this out with your name and url ↓ -->
			<p>Created by <a href="http://todomvc.com">you</a></p>
			<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
		</footer>
		<!-- Scripts here. Don't remove ↓ -->
		<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
		<script src="node_modules/todomvc-common/base.js"></script>
		<script src="js/app.js"></script>
	</body>
	
</html>

页面展示:

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值