Vue todos代办事项功能

这篇博客详细介绍了如何使用Vue.js实现todos待办事项的功能,包括创建工程和组件、铺设待办任务、添加任务、删除任务、底部统计、数据切换、清空已完成任务以及数据缓存。通过讲解各个步骤,涵盖了Vue的基础语法、组件化开发、事件处理、数据绑定等技术点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天做的笔记是todos 待办事项项目  

相信大家学完vue基础后,迫不及待想实现一些功能.所以这里我会用到Vue基础语法 和一些js的知识来互相结合运用

可能写的笔记不太好  大家耐心观看,有意见可以在评论区留言.我不会分享源码哦,大家想要源码还是自己看一遍敲出来最好的.

自行创建目录下的子组件 和样式css

todos-创建工程和组件

目录情况如下

 

 base.css内容如下

hr {
	margin: 20px 0;
	border: 0;
	border-top: 1px dashed #c5c5c5;
	border-bottom: 1px dashed #f7f7f7;
}

.learn a {
	font-weight: normal;
	text-decoration: none;
	color: #b83f45;
}

.learn a:hover {
	text-decoration: underline;
	color: #787e7e;
}

.learn h3,
.learn h4,
.learn h5 {
	margin: 10px 0;
	font-weight: 500;
	line-height: 1.2;
	color: #000;
}

.learn h3 {
	font-size: 24px;
}

.learn h4 {
	font-size: 18px;
}

.learn h5 {
	margin-bottom: 0;
	font-size: 14px;
}

.learn ul {
	padding: 0;
	margin: 0 0 30px 25px;
}

.learn li {
	line-height: 20px;
}

.learn p {
	font-size: 15px;
	font-weight: 300;
	line-height: 1.3;
	margin-top: 0;
	margin-bottom: 0;
}

#issue-count {
	display: none;
}

.quote {
	border: none;
	margin: 20px 0 60px 0;
}

.quote p {
	font-style: italic;
}

.quote p:before {
	content: '“';
	font-size: 50px;
	opacity: .15;
	position: absolute;
	top: -20px;
	left: 3px;
}

.quote p:after {
	content: '”';
	font-size: 50px;
	opacity: .15;
	position: absolute;
	bottom: -42px;
	right: 3px;
}

.quote footer {
	position: absolute;
	bottom: -40px;
	right: 0;
}

.quote footer img {
	border-radius: 3px;
}

.quote footer a {
	margin-left: 5px;
	vertical-align: middle;
}

.speech-bubble {
	position: relative;
	padding: 10px;
	background: rgba(0, 0, 0, .04);
	border-radius: 5px;
}

.speech-bubble:after {
	content: '';
	position: absolute;
	top: 100%;
	right: 30px;
	border: 13px solid transparent;
	border-top-color: rgba(0, 0, 0, .04);
}

.learn-bar > .learn {
	position: absolute;
	width: 272px;
	top: 8px;
	left: -300px;
	padding: 10px;
	border-radius: 5px;
	background-color: rgba(255, 255, 255, .6);
	transition-property: left;
	transition-duration: 500ms;
}

@media (min-width: 899px) {
	.learn-bar {
		width: auto;
		padding-left: 300px;
	}

	.learn-bar > .learn {
		left: 8px;
	}
}

index.css样式如下

html,
body {
	margin: 0;
	padding: 0;
}

button {
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	font-size: 100%;
	vertical-align: baseline;
	font-family: inherit;
	font-weight: inherit;
	color: inherit;
	-webkit-appearance: none;
	appearance: none;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

body {
	font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
	line-height: 1.4em;
	background: #f5f5f5;
	color: #111111;
	min-width: 230px;
	max-width: 550px;
	margin: 0 auto;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	font-weight: 300;
}

:focus {
	outline: 0;
}

.hidden {
	display: none;
}

.todoapp {
	background: #fff;
	margin: 130px 0 40px 0;
	position: relative;
	box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2),
	            0 25px 50px 0 rgba(0, 0, 0, 0.1);
}

.todoapp input::-webkit-input-placeholder {
	font-style: italic;
	font-weight: 300;
	color: rgba(0, 0, 0, 0.4);
}

.todoapp input::-moz-placeholder {
	font-style: italic;
	font-weight: 300;
	color: rgba(0, 0, 0, 0.4);
}

.todoapp input::input-placeholder {
	font-style: italic;
	font-weight: 300;
	color: rgba(0, 0, 0, 0.4);
}

.todoapp h1 {
	position: absolute;
	top: -140px;
	width: 100%;
	font-size: 80px;
	font-weight: 200;
	text-align: center;
	color: #b83f45;
	-webkit-text-rendering: optimizeLegibility;
	-moz-text-rendering: optimizeLegibility;
	text-rendering: optimizeLegibility;
}

.new-todo,
.edit {
	position: relative;
	margin: 0;
	width: 100%;
	font-size: 24px;
	font-family: inherit;
	font-weight: inherit;
	line-height: 1.4em;
	color: inherit;
	padding: 6px;
	border: 1px solid #999;
	box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
	box-sizing: border-box;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

.new-todo {
	padding: 16px 16px 16px 60px;
	border: none;
	background: rgba(0, 0, 0, 0.003);
	box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03);
}

.main {
	position: relative;
	z-index: 2;
	border-top: 1px solid #e6e6e6;
}

.toggle-all {
	width: 1px;
	height: 1px;
	border: none; /* Mobile Safari */
	opacity: 0;
	position: absolute;
	right: 100%;
	bottom: 100%;
}

.toggle-all + label {
	width: 60px;
	height: 34px;
	font-size: 0;
	position: absolute;
	top: 12px;
	left: -13px;
	-webkit-transform: rotate(90deg);
	transform: rotate(90deg);
	z-index: 9999
}

.toggle-all + label:before {
	content: '❯';
	font-size: 22px;
	color: #e6e6e6;
	padding: 10px 27px 10px 27px;
}

.toggle-all:checked + label:before {
	color: #73737
### 如何用 Vue.js 实现待办事项功能 要实现一个基于 Vue.js待办事项功能,可以通过创建一个简单的单页应用程序来完成。以下是其实现的核心逻辑和技术细节。 #### 1. 初始化目 首先需要初始化一个新的 Vue 目。如果尚未安装 Vue CLI 工具,则需先全局安装它: ```bash npm install -g @vue/cli ``` 接着使用 Vue CLI 创建新目并选择默认配置: ```bash vue create todo-list-vue cd todo-list-vue ``` 这一步骤会设置好目的开发环境和依赖[^3]。 #### 2. 构建基本界面 在 `src/App.vue` 文件中定义基础布局,包括输入框用于添加新的待办事项、按钮触发新增操作以及列表显示当前所有的待办事项。 ```html <template> <div id="app"> <h1>我的待办清单</h1> <input v-model="newTodoText" placeholder="请输入待办事项..." /> <button @click="addNewTodo">添加</button> <ul> <li v-for="(todo, index) in todos" :key="index"> {{ todo }} <button @click="removeTodo(index)">删除</button> </li> </ul> </div> </template> <script> export default { data() { return { newTodoText: '', todos: [] }; }, methods: { addNewTodo() { if (this.newTodoText.trim()) { this.todos.push(this.newTodoText); this.newTodoText = ''; } }, removeTodo(index) { this.todos.splice(index, 1); } } }; </script> ``` 上述码展示了如何绑定数据模型至视图层,并通过事件监听器处理用户的交互行为[^1]。 #### 3. 添加样式优化用户体验 为了提高视觉效果,在同一文件内的 `<style>` 部分加入一些 CSS 样式规则: ```css <style scoped> #app { font-family: Avenir, Helvetica, Arial, sans-serif; text-align: center; } input[type='text'] { padding: 8px; margin-right: 10px; width: 70%; } button { padding: 8px 16px; } ul { list-style-type: none; padding-left: 0; } li { margin-top: 10px; } </style> ``` 这些样式使得页面更加美观易读[^2]。 #### 4. 运行与测试应用 最后启动本地服务器查看实际运行情况: ```bash npm run serve ``` 打开浏览器访问指定地址即可看到实时更新的应用程序界面。 --- ### 总结 通过以上方法能够快速搭建起一个具备增删功能的基础版待办事项管理系统。随着技能的增长还可以继续扩展更多高级特性和复杂业务场景的支持。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值