Vue待办事项(选项卡)

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

<style>

* {

padding: 0;

margin: 0;

}

ul,

ol {

list-style: none;

}

.header {

width: 400px;

margin: 0px auto;

margin-top: 50px;

box-shadow: 1px 1px 5px 5px;

}

.input {

padding: 10px;

height: 30px;

display: flex;

}

.input input {

padding-left: 10px;

flex: 1;

}

.input button {

width: 60px;

height: 30px;

}

.text {

padding: 10px;

display: flex;

}

.text .list {

flex: 1;

background-color: aliceblue;

text-align: center;

cursor: pointer;

}

/* .text div:nth-child(1){

background-color: black;

color: white;

} */

.cart {

padding: 10px;

}

.cart li {

height: 20px;

display: flex;

margin-bottom: 10px;

}

.cart li div {

flex: 1;

padding-left: 10px;

}

.cart li input {

height: 20px;

width: 20px;

}

.clear {

padding: 10px;

display: flex;

}

.clear div {

flex: 1;

}

.list.active {

background-color: black;

color: white;

}

</style>

</head>

<body>

<div class="header" id="app">

<div class="input">

<input type="text" placeholder="请输入" ref="inputref" v-model="message" />

<button @click="haddleadd()">添加</button>

</div>

<div class="text">

<div class="list" :class="type=='all'? 'active' : '' " @click="check('all')">所有待办事项({{arr.length}})

</div>

<div class="list" :class="type=='some'? 'active' : '' " @click="check('some')">

已完成({{computetode.length}})</div>

<div class="list" :class="type=='every'? 'active' : '' " @click="check('every')">

未完成({{uncomputetode.length}})</div>

</div>

<div class="cart">

<!-- <h3>所有</h3> -->

<ul>

<li v-for="item in currentarr" :key="item.id">

<input type="checkbox" v-model="item.complate" />

<div>{{item.text}}</div>

<button @click="remove(item.id)">删除</button>

</li>

</ul>

</div>

<!-- <div class="cart">

<h3>已完成</h3>

<ul>

<li v-for="item in computetode" :key="item.id">

<input type="checkbox" v-model="item.complate"/>

<div>{{item.text}}</div>

<button >删除</button>

</li>

</ul>

</div>

<div class="cart">

<h3>未完成</h3>

<ul>

<li v-for="item in uncomputetode" :key="item.id">

<input type="checkbox" v-model="item.complate"/>

<div>{{item.text}}</div>

<button >删除</button>

</li>

</ul>

</div> -->

<div class="clear">

<div></div>

<button @click="removeall()">清除</button>

</div>

</div>

<script src="lib/vue.global.js"></script>

<script>

var todeid = 1

</script>

<script>

const {

createApp

} = Vue

const app = createApp({

data() {

return {

message: '',

arr: [],

type: 'all',

currentarr: []

}

},

computed: {

computetode() {

return this.arr.filter(item => item.complate == true)

},

uncomputetode() {

return this.arr.filter(item => item.complate == false)

},

},

methods: {

haddleadd() {

this.$refs.inputref.focus()

if (this.message.trim() != '') {

this.arr.push({

id: todeid++,

complate: false,

text: this.message.trim()

})

}

console.log(this.arr)

},

remove(id){

this.arr=this.arr.filter(item=>item.id!=id)

},

removeall(){

this.arr=[]

},

check(types) {

this.type = types

}

},

watch: {

uncomputetode() {

if (this.type == 'every') {

this.currentarr = this.uncomputetode

} else if (this.type == 'some') {

this.currentarr = this.computetode

} else {

this.currentarr =this.arr

}

},

type: {

handler(newtype) {

console.log(newtype)

switch (newtype) {

case 'all':

this.currentarr = this.arr

break

case 'some':

this.currentarr = this.computetode

break

case 'every':

this.currentarr = this.uncomputetode

break

}

},

immediate: true,

},

}

})

app.mount('#app')

</script>

</body>

</html>

相关推荐
candyTong2 小时前
一觉醒来,大模型就帮我排查完页面性能问题
前端·javascript·架构
魔术师Grace2 小时前
我给 AI 做了场入职培训
前端·程序员
玩嵌入式的菜鸡3 小时前
网页访问单片机设备---基于mqtt
前端·javascript·css
前端一小卒3 小时前
我用 Claude Code 的 Superpowers 技能链写了个服务,部署前差点把服务器搞炸
前端·javascript·后端
滑雪的企鹅.4 小时前
HTML头部元信息避坑指南大纲
前端·html
一拳不是超人4 小时前
老婆天天吵吵要买塔罗牌,我直接用 AI 2 小时写了个在线塔罗牌
前端·ai编程
阿丰资源6 小时前
SpringBoot+Vue实战:打造企业级在线文档管理系统
vue.js·spring boot·后端
excel6 小时前
如何解决 Nuxt DevTools 中关于 unstorage 包的报错
前端
Rust研习社6 小时前
使用 Axum 构建高性能异步 Web 服务
开发语言·前端·网络·后端·http·rust
C澒6 小时前
AI 生码 - API2Code:接口智能匹配与 API 自动化生码全链路设计
前端·低代码·ai编程