布局与样式
一个TodoList长什么样子相信无需多言:

上样式:
src/TodoList.css
.td-wrapper {
width: 700px;
margin: 0 auto;
}
.dp-wrapper {
width: 100%;
height: 40px;
display: flex;
margin-top: 10px;
}
.dp-wrapper input {
flex: 4;
height: 36px;
line-height: 36px;
text-indent: 10px;
font-size: 1rem;
}
.dp-wrapper button {
flex: 1;
height: 100%;
margin-left: 2px;
font-size: 1rem;
}
.dl-wrapper {
border: 1px solid gray;
margin-top: 5px;
}
.dl-wrapper li {
height: 40px;
line-height: 40px;
border-bottom: 1px solid gray;
}
.dl-wrapper li.done {
text-decoration: line-through;
}
.dl-wrapper li:last-child {
border-bottom: none;
}
创建工程
npm init vite@latest
后续选择:react + ts
添加必要文件,工程结构如下:

定义全局数据类型
src/vite-env.d.ts
/// <reference types="vite/client" />
/* 代办事项数据结构 */
interface TodoItem {
name: string,
done: boolean
}

本文通过Vite搭建React项目,结合TypeScript,详细介绍了如何创建TodoList应用,包括布局与样式设定、工程初始化、全局数据类型定义以及组件的实现,提供了完整的源码地址。
最低0.47元/天 解锁文章
173

被折叠的 条评论
为什么被折叠?



