[第一篇](Vue2零基础写一个todolist(一) - 掘金 (juejin.cn))
现在我们来开始写第一个页面。
首先在src目录下新建view目录,之后的代码都写在这个目录下。
在view目录下新建文件夹todoList,在todoList文件夹里新建文件index.vue
打开router文件夹下的index.js
在import HelloWorld from '@/components/HelloWorld'前面加两条//注释掉代码,将代码结构改为这样。
打开App.vue,删除img,删除style里的所有样式。
在view/todoList/index.vue里编写代码
保存后页面上就会显示hello world,这就是用vue写的第一个页面。
之后我们对这个todolist进行分析,根据图片的布局将这个todolist分为两个部分来写。
首先在最外层的index.html的index.html里把body{margin:0}
然后回到view/todoList/index.vue正式编写代码,先把页面样式写出来。
<template>
<div>
<div class="title">欢迎使用todolist</div>
<div class="content">
<div class="input-content">
<div class="input-conten-title">添加任务:</div>
<input class="input" type="text" name="" id="" placeholder="回车即可添加任务" v-model="mission">
</div>
<div class="input-handle">
<div class="left">
3个任务未完成
</div>
<div class="right">
<div class="right-button">
所有任务
</div>
<div class="right-button">
未完成
</div>
<div class="right-button">
已完成
</div>
</div>
</div>
<div class="list-content">
<div class="list-title">任务列表:</div>
<div class="list-box">
<div class="list-item">
<span class="list-check-box">
<span class="list-check-show">√</span>
</span>
<span>
123456
</span>
</div>
<div class="list-item">
<span class="list-check-box">
<span class="list-check-show">√</span>
</span>
<span>
123456
</span>
</div>
<div class="list-item">
<span class="list-check-box">
<span class="list-check-show">√</span>
</span>
<span>
123456
</span>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
.title {
background: rgb(250, 83, 83);
text-align: center;
color: white;
line-height: 40px;
height: 40px;
}
.content {
width: 50%;
margin: 0 auto;
}
.input-conten-title,
.list-title {
font-size: 24px;
font-weight: bold;
margin: 10px 0;
}
.list-item {
line-height: 40px;
border-bottom: 1px solid #cccccc;
}
.list-check-box {
height: 16px;
padding: 0 5px;
border: 1px solid #cccccc;
border-radius: 50%;
}
.list-check-show {
color: rgb(149, 189, 136);
}
.list-check-hidden {
visibility: hidden;
}
.list-check-decoration {
text-decoration: line-through;
color: #cccccc;
}
.input {
width: 100%;
margin: 10px 0;
height: 30px;
}
.input-handle {
display: flex;
justify-content: space-between;
margin: 10px 0;
}
.left {
color: tomato;
}
.right {
display: flex;
}
.right-button {
margin: 0 5px;
padding: 0 5px;
}
.right-button-border {
border: 1px solid #cccccc;
padding: 0 5px;
}
</style>>