Vue待办事项(组件,模块化)

//html页面代码

<!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;

text-align: center;

cursor: pointer;

}

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

background-color: black;

color: white;

} */

.text .active {

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;

}

</style>

</head>

<body>

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

<my-input @add="addcartin"></my-input>

<my-text :type="type" @blue="tab" :computetode="computetode" :uncomputetode="uncomputetode" :arr="arr"></my-text>

<my-cart :list=" currentarr" @remove="remove" ></my-cart>

<my-clear @clear="removeall"></my-clear>

</div>

<script type="module">

import { createApp } from './lib/vue.esm-browser.js'

import AddOptions from './components/tode-input.js'

import AddText from './components/tode-text.js'

import AddCart from './components/tode-cart.js'

import AddFooter from './components/tode-footer.js'

var itemid=1

const app = createApp({

data() {

return {

arr:\[\],

type:'all',

currentarr:\[\]

}

},

computed: {

computetode() {

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

},

uncomputetode() {

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

},

},

methods:{

addcartin(title){

this.arr.push({

id:itemid++,

complate:false,

title

})

},

removeall(data){

this.arr=data

},

remove(id){

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

},

tab(data){

this.type=data

}

},

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.component('MyInput', AddOptions)

app.component('MyText',AddText)

app.component('MyCart',AddCart)

app.component('MyClear',AddFooter)

app.mount('#app')

</script>

</body>

</html>

//tode-cart.js代码

var AddCart={

template:`

<div class="cart">

<ul>

<li v-for="item in list">

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

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

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

</li>

</ul>

</div>

`,

props: 'list',

methods:{

remove(id){

this.$emit('remove',id)

}

}

}

export default AddCart

//tode-footer.js代码

var AddFooter={

template:`

<div class="clear">

<div></div>

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

</div>

`

,

methods:{

removeall(data){

this.$emit('clear',\[\])

}

},

}

export default AddFooter

//tode-input.js代码

var AddOptions={

template:`

<div class="input">

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

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

</div>

`,

data(){

return{

message:''

}

},

methods:{

haddleadd(data){

this.$emit("add",this.message)

}

}

}

export default AddOptions

//tode-text.js代码

var AddText={

template:`

<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>

`,

props:'type','arr','uncomputetode','computetode',

methods:{

check(item){

this.$emit('blue',item)

}

}

}

export default AddText

相关推荐
福兮说2 分钟前
URL 编码的七个坑:c++ 传到后端变空格、%25 套娃、截断 emoji 直接报错
开发语言·前端·javascript·node.js·url
吴声子夜歌8 分钟前
Nginx应用与运维——Nginx Web服务应用实战(Python网站的搭建)
运维·前端·nginx
小的时候可菜了26 分钟前
JS 异步的本质:从单线程到 thenable(一条进化链)
开发语言·前端·javascript
liangshanbo121532 分钟前
Webpack vs Vite 底层原理高频追问的问题
前端·webpack·node.js
可乐鸡翅yeah_34 分钟前
hls.js 配置 loadStartPosition,点播起始播放位置踩坑
开发语言·javascript·网络协议·ecmascript·m3u8在线
web打印社区1 小时前
Windows 网页静默打印设置步骤:客户端、防火墙与联调清单
开发语言·前端·javascript·chrome·pdf·ecmascript
恋猫de小郭1 小时前
KMP 又改了编译流程, Separate Compilation 禁止了 `commonMain` 的依赖穿透
android·前端·flutter
吴声子夜歌1 小时前
Nginx应用与运维——Nginx Web服务应用实战(静态文件服务器的搭建)
运维·前端·nginx
y = xⁿ1 小时前
关于Agent工程落地
前端·人工智能·python
web打印社区2 小时前
JS 静默打印怎么做:纯前端为什么不行,以及最小可跑通写法
开发语言·前端·javascript·websocket·网络协议·http·pdf