uniapp开发app框架在提升开发效率中的独特优势与应用探索
503
2022-12-16
vue3实现一个todo
目录功能介绍相关代码总结
实现方式不是最优,主要是为了学习vue3的一些新语法以及属性
功能介绍
相关代码
index.vue
工作计划
class="button" type="primary" icon="el-icon-circle-plus" circle @click="handleClickTodo" >
class="button"
type="primary"
icon="el-icon-circle-plus"
circle
@click="handleClickTodo"
>
v-for="(val, index) in list" :key="index" :info="val" >
v-for="(val, index) in list"
:key="index"
:info="val"
>
import AddAction from "./AddTodo.vue";
import TodoItem from "./Item.vue";
import { reactive, toRefs, provide } from "vue";
export default {
name: "todo-list",
components: { AddAction, TodoItem },
setup() {
const state = reactive({
visible: false,
list: [
{
title: "1.学习vue3.0",
time: "2021-08-20",
desc: "1.ppppppppppppp",
status: false,
},
],
});
const addTodo = (data) => {
state.list.push(data);
};
const delTodo = (title) => {
state.list = state.list.filter((val) => val.title !== YNTjbtitle);
};
const handleClickTodo = () => {
state.visible = true;
};
provide("addTodo", addTodo);
provide("delTodo", delTodo);
return {
handleClickTodo,
...toRefs(state),
};
},
};
.todo-list {
padding: 100px;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.text {
font-size: 14px;
}
.item {
margin-bottom: 18px;
}
.box-card {
width: 480px;
}
AddTodo.vue
title="新增待办计划" v-model="visible" width="600px" @close="handleClose" > style="width: 430px" :model="form" :rules="rules" label-width="120px" ref="formRef" > v-model="form.title" placeholder="请输入待办计划名称" > type="textarea" :rows="6" v-model="form.desc" placeholder="请输入详细待办计划" >
title="新增待办计划"
v-model="visible"
width="600px"
@close="handleClose"
>
style="width: 430px" :model="form" :rules="rules" label-width="120px" ref="formRef" > v-model="form.title" placeholder="请输入待办计划名称" > type="textarea" :rows="6" v-model="form.desc" placeholder="请输入详细待办计划" >
style="width: 430px"
:model="form"
:rules="rules"
label-width="120px"
ref="formRef"
>
v-model="form.title" placeholder="请输入待办计划名称" >
v-model="form.title"
placeholder="请输入待办计划名称"
>
type="textarea" :rows="6" v-model="form.desc" placeholder="请输入详细待办计划" >
type="textarea"
:rows="6"
v-model="form.desc"
placeholder="请输入详细待办计划"
>
import { reactive, toRefs, ref, inject } from "vue";
export default {
name: "add-todo",
props: {
visible: {
type: Boolean,
default: false,
},
},
setup(props, { emit }) {
const formRef = YNTjbref(null)
const addTodo = inject('addTodo')
const state = reactive({
form: {
title: "",
desc: "",
time: "",
status: false
},
rules: {
title: [
{ required: true, message: '请输入待办计划名称', trigger: ['blur']}
],
time: [
{ required: true, message: '请选择待办计划时间', trigger: ['change']}
],
desc: [
{ required: true, message: '请输入详细待办计划', trigger: ['blur']}
]
},
});
const handleClose = () => {
emit("update:visible", false);
formRef.value.clearValidate()
formRef.value.resetFields()
};
const handleConfirm = () => {
formRef.value.validate(valid => {
if (valid) {
addTodo(jsON.parse(JSON.stringify(state.form)))
handleClose()
}
})
}
return {
formRef,
...toRefs(state),
handleClose,
handleConfirm
};
},
};
Item.vue
{{ info.time }}
type="danger" icon="el-icon-delete" circle size="mini" @click="handleDelTodo" >
type="danger"
icon="el-icon-delete"
circle
size="mini"
@click="handleDelTodo"
>
import { inject } from "vue";
export default {
name: "todo-item",
props: {
info: {
type: Object,
default: () => ({}),
},
},
setup(props) {
const delTodo = inject("delTodo");
const handleDelTodo = () => {
delTodo(props.info.title);
};
return {
handleDelTodo,
};
},
};
.todo-item {
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid rgb(229, 226, 226);
height: 45px;
line-height: 45px;
.success {
text-decoration: line-through;
}
.titme-box {
display: flex;
align-items: center;
h3 {
padding-left: 12px;
font-size: 16px;
}
}
.del {
display: flex;
align-items: center;
.time {
width: 100px;
font-size: 14px;
}
}
}
总结
本篇文章就到这里了,希望能给你带来帮助,也希望您能够多多关注我们的更多内容!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~