web蓝桥杯真题:时间管理大师

代码及注释:

<div id="box">
<div class="head">
	<h2>Todos</h2>
	<p>罗列日常计划,做一个时间管理大师!</p>
	<div class="input">
		<span>内容</span>
		<input type="text" v-model="search" placeholder="请输入你要做的事"/>
		<span id='add' @click="addTodo">确认</span>    //绑定事件
	</div>
</div>

<ul class="list">
	<li v-if="!todoList.length">    //数组为空时
		暂无数据
	</li>
	<li v-if="todoList.length" v-for="(todo, index) in todoList" :key="index">  //数组不为空时,循环数组
		<!-- 前面的序号 -->
		<span class="xh">{{index + 1}}</span>    //索引值+1
		<!-- 列表内容 -->
		<span>{{todo}}</span>
		<!-- 删除按钮 -->
		<span class="qc" @click="deleteTodo(index)"></span> //传递索引值,定位需要删除的元素
	</li>
	<li v-if="todoList.length">
		<b>
			总数:{{todoList.length}}
		</b>
		<b id='clear' @click="clear">清除</b>
	</li>
</ul>
</div>
var top= new Vue({
	el:"#box",
	// 在此处补全代码,实现所需功能
	data: {
			todoList: [],
			search: ''
	},
	//   获取搜索内容
	methods: {
		// 添加
		addTodo() {
			this.todoList.push(this.search)  //将搜索值插入数组
		},
		// 删除
		deleteTodo(index) {        
			this.todoList.splice(index, 1)    //获取索引值,定位删除元素,进行元素删除
		},
		// 清除
		clear() {
			this.todoList=[]    //数组重置为空
		}
	}
})

知识点:

1.数组分割
array.splice(startIndex, howmany)进行元素删除,该方法会改变原数组

相关推荐

  1. web时间管理大师

    2024-03-18 22:40:02       42 阅读
  2. Web大学组)2022国赛:新鲜的蔬菜

    2024-03-18 22:40:02       52 阅读
  3. Web大学组)2022省赛:展开你的扇子

    2024-03-18 22:40:02       53 阅读
  4. Web大学组)2022省赛:冬奥大抽奖

    2024-03-18 22:40:02       50 阅读
  5. Web大学组)2023省赛:视频弹幕

    2024-03-18 22:40:02       57 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-18 22:40:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-18 22:40:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-03-18 22:40:02       82 阅读
  4. Python语言-面向对象

    2024-03-18 22:40:02       91 阅读

热门阅读

  1. 基于SpringBoot+Druid实现多数据源:baomidou多数据源

    2024-03-18 22:40:02       44 阅读
  2. centos系统ssh7.4升级9.6

    2024-03-18 22:40:02       34 阅读
  3. 【C++】map与set容器的应用总结

    2024-03-18 22:40:02       41 阅读
  4. ceph删除坏的磁盘

    2024-03-18 22:40:02       45 阅读
  5. spring学习源码第一课

    2024-03-18 22:40:02       31 阅读