实现了增、删功能,任务统计,全删除功能。
文章来源地址https://www.toymoban.com/news/detail-715111.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<body>
<div id="app">
<input placeholder="请输入待执行的任务" v-model="todoName">
<button @click="add">添加任务</button>
<ul>
<li v-for="(item,index) in list" :key="item.id">
{{index+1}} {{item.name}}
<button @click="del(item.id)">删除</button>
</li>
</ul>
<div>
合计:{{list.length}}
<button @click="clear">清空任务</button>
</div>
</div>
<script>
const app = new Vue({
el: "#app",
data: {
todoName: '',
list: [
{ id: 1, name: '跑步一公里' }
]
},
methods: {
del(id) {
confirm('是否删除该任务?')
this.list = this.list.filter(item => item.id !== id)
},
add() {
if (this.todoName.trim() == '') {
alert('请输入有效内容')
return
}
this.list.unshift({
id: +new Date(),
name: this.todoName
})
this.todoName = ''
},
clear() {
this.list = []
}
}
})
</script>
</body>
</html>
文章来源:https://www.toymoban.com/news/detail-715111.html
到了这里,关于vue实现记事本(无样式版)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!