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>

相关推荐
2501_9444480024 分钟前
Flutter for OpenHarmony衣橱管家App实战:支持我们功能实现
android·javascript·flutter
人工智能训练6 小时前
【极速部署】Ubuntu24.04+CUDA13.0 玩转 VLLM 0.15.0:预编译 Wheel 包 GPU 版安装全攻略
运维·前端·人工智能·python·ai编程·cuda·vllm
会跑的葫芦怪6 小时前
若依Vue 项目多子路径配置
前端·javascript·vue.js
xiaoqi9227 小时前
React Native鸿蒙跨平台如何进行狗狗领养中心,实现基于唯一标识的事件透传方式是移动端列表开发的通用规范
javascript·react native·react.js·ecmascript·harmonyos
jin1233228 小时前
React Native鸿蒙跨平台剧本杀组队消息与快捷入口组件,包含消息列表展示、快捷入口管理、快捷操作触发和消息详情预览四大核心功能
javascript·react native·react.js·ecmascript·harmonyos
烬头88219 小时前
React Native鸿蒙跨平台实现二维码联系人APP(QRCodeContactApp)
javascript·react native·react.js·ecmascript·harmonyos
pas1369 小时前
40-mini-vue 实现三种联合类型
前端·javascript·vue.js
摇滚侠9 小时前
2 小时快速入门 ES6 基础视频教程
前端·ecmascript·es6
2601_949833399 小时前
flutter_for_openharmony口腔护理app实战+预约管理实现
android·javascript·flutter
珑墨10 小时前
【Turbo】使用介绍
前端