前言
寒假待在家,无所事事,便开始做起了毕设,由于要写跨端应用,基础是vue,所以先攻克vue
做一个简单的todo 当然是自己做的,效率有点儿低,不过能做出来已经很不错了把 hhh
源码
本质上毕设的前端展示,也就是对一个todo-list加一个好看的ui,数据排版等等花里胡哨的东西,本质的东西还是数据的crud
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>todo-list</title>
<script src="https://cdn.bootcss.com/vue/2.6.8/vue.min.js"></script>
</head>
<body>
<div id="todo-list-demo">
请输入要添加的 todo <br>
<input type="text" v-model="todoText" placeholder="输入要添加的todo">
<input type="submit" @click="addTodo" value="add todo"/>
<div>
<ol>
<li v-for="todoItem in todoData" v-key="todoItem.id">
{{todoItem.title}}
<input type="submit" value="remove todo" @click="removeTodo(todoItem.id)">
</li>
</ol>
</div>
</div>
<script type="text/javascript">
var todo = new Vue({
el: "#todo-list-demo",
data: {
todoText: "",
todoIndex: 2,
todoData: [{
id: 0,
title: "刷牙",
}, {
id: 1,
title: "洗脸"
}]
},
methods: {
addTodo: function() {
this.todoData.push({id: this.todoIndex++, title: this.todoText})
// 新增加一个todo, 就清空原有输入
this.todoText = ""
},
removeTodo: function(id) {
index = 0;
// console.dir(this.todoData)
for (var i = 0; i < this.todoData.length; ++i) {
if (this.todoData[i].id === id) {
this.todoData.splice(index, 1)
}
index ++;
}
}
}
})
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/Draymonder/p/12240053.html
时间: 2024-11-05 23:36:40