1 Star 0 Fork 4

沢原浩輔/clock

forked from 花果山大圣/clock 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vue.html 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
花果山大圣 提交于 2021-09-06 02:59 . vue3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.done{
color:gray;
text-decoration: line-through;
}
</style>
</head>
<body>
<div id="app">
hello {{name}}
<div>
<input type="text" v-model="val">
<button @click="add">新增</button>
<button @click="clear"> 清除已完成 </button>
<ul>
<li v-for="todo in todos" :class="{done:todo.done}">
<input type="checkbox" v-model="todo.done">
{{todo.title}}
</li>
</ul>
<div>
{{active}} / {{all}}
</div>
</div>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
let todos = localStorage.getItem('todos')
const App = {
data(){
return {
name:'亚瑟',
val:"",
todos:todos?JSON.parse(todos) :[
{title:'吃饭',done:true},
{title:'睡觉',done:false},
{title:'打王者',done:false},
]
}
},
computed:{
active(){
return this.todos.filter(v=>!v.done).length
},
all(){
return this.todos.length
}
},
watch:{
todos:{
handler(val){
localStorage.setItem('todos',JSON.stringify(val))
},
deep:true
}
},
methods:{
add(){
this.todos.push({
title:this.val,
done:false
})
this.val = ''
},
clear(){
this.todos = this.todos.filter(v=>!v.done)
}
}
}
Vue.createApp(App).mount('#app')
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sako-suke/clock.git
git@gitee.com:sako-suke/clock.git
sako-suke
clock
clock
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385