Vue实现todolist

一、需求分析

  1. 代办事项的添加,删除,完成
  2. 计时器
  3. 登录和注册

二、技术支持

  1. Vue
  2. js
  3. 路由
  4. localstorage

三、页面展示

在这里插入图片描述
在这里插入图片描述

四、代码实现

  1. App.vue
<template>
  <div id="app">
    <router-view>
      
    </router-view>
  </div>
</template>


<script>
export default {
  name: "App",
};
</script>

<style scoped>

</style>

  1. Login.vue
<template>
  <form>
    <div class="title">Login</div>
    <input class="username" placeholder="User name" v-model="username" />
    <div class="error">{{ uError }}</div>
    <input type="password" class="password" placeholder="Password" v-model="userpwd" />
    <div class="error">{{ pError }}</div>
    <button class="register-btn" @click="userRegister">Login</button>
    <div class="Changing">
      <button class="a b">已经注册,返回登录</button>
    <button class="a b" @click="GetRegister">还没注册,点击注册</button>
    </div>
  </form>
</template>
<script>
export default {
  name: "Login",
  data: function () {
    return {
      username: "",
      userpwd: "",
      pwdagain: "",
      uError: "",
      pError: "",
      aError: "",
    };
  },
  //methods 用于定义的函数。
  methods: {
    //这里定义了一个用户注册函数
    userRegister: function () {
      //简单进行一下验证,判断是否为空
      //正经项目肯定需要更多的验证规则,这里只是提供一个思路
      if (this.username == "") {
        this.uError = "用户名不能为空!";
      } else {
        this.uError = "";
      }
      if (this.userpwd == "") {
        this.pError = "密码不能为空!";
      } else {
        this.pError = "";
      }
      if (this.uError == "" && this.pError == "" && this.aError == "") {
        this.$router.push("/Home");
      }
    },
    GetRegister(){
      this.$router.push("/Register")
    }
  },
};
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
  color: rgb(95, 95, 95);
}
li,
ul,
ol {
  list-style: none;
}
.cointer {
  width: 600px;
  margin: 0 auto;
}
form {
  margin: auto;
  width: 498px;
  height: 340px;
  color: white;
  border: 1px solid white;
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.5);
}

.title {
  margin-top: 20px;
  margin-bottom: 20px;
  font-size: 30px;
}

input {
  width: 100%;
  height: 40px;
  background-color: rgba(18, 121, 206, 0.321);
  padding-left: 5px;
  border-radius: 5px;
}

button {
  width: 100px;
  height: 30px;
  margin-bottom: 20px;
}

form a {
  display: block;
  margin-bottom: 10px;
  cursor: pointer;
}

.error {
  font-size: 14px;
  color: red;
  height: 20px;
}

.a {
  text-decoration: none;
  color: rgb(222, 222, 222);
  width: 250px;
  line-height: 100%;
  height: 100%;
}
.Changing {
  width: 500px;
  height: 50px;
  margin: 0 auto;
  display: flex;
  text-align: center;
  /* align-items: center; */
  justify-content: center;
  background-color: rgb(0, 119, 255);
}
.b {
  background-color: rgb(96, 164, 243);
}
</style>

  1. Register.vue
<template>
  <form>
    <div class="title">Register</div>
    <input class="username" placeholder="User name" v-model="username" />
    <div class="error">{{ uError }}</div>
    <input type="password" class="password" placeholder="Password" v-model="userpwd" />
    <div class="error">{{ pError }}</div>
    <input type="password" class="pwdagain" placeholder="Confirm Password" v-model="pwdagain" />
    <div class="error">{{ aError }}</div>
    <button class="register-btn" @click="userRegister">Register</button>
    <div class="Changing">
      <button class="a b" @click="GetLogin">已经注册,返回登录</button>
    <button class="a b" >还没注册,点击注册</button>
    </div>
  </form>
</template>
<script>
export default {
  //这里是组件的名字,无影响
  name: "Register",
  data: function () {
    return {
      //这里主要是初始化用户输入的信息,以及错误提示
      username: "",
      userpwd: "",
      pwdagain: "",
      uError: "",
      pError: "",
      aError: "",
    };
  },
  //methods 用于定义的函数。
  methods: {
    //这里定义了一个用户注册函数
    userRegister: function () {
      if (this.username == "") {
        this.uError = "用户名不能为空!";
      } else {
        this.uError = "";
      }
      if (this.userpwd == "") {
        this.pError = "密码不能为空!";
      } else {
        this.pError = "";
      }
      if (this.userpwd != this.pwdagain) {
        this.aError = "两次密码不一致!";
      } else {
        this.aError = "";
      }
      if (this.uError == "" && this.pError == "" && this.aError == "") {
        this.$router.push("/Login");
      }
    },
    GetLogin(){
      this.$router.push("/Login")
    }
  },
};
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
  color: rgb(95, 95, 95);
}
li,
ul,
ol {
  list-style: none;
}
.cointer {
  width: 600px;
  margin: 0 auto;
}
form {
  margin: auto;
  width: 498px;
  height: 340px;
  color: white;
  border: 1px solid white;
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.5);
}

.title {
  margin-top: 20px;
  margin-bottom: 20px;
  font-size: 30px;
}

input {
  width: 100%;
  height: 40px;
  background-color: rgba(18, 121, 206, 0.321);
  padding-left: 5px;
  border-radius: 5px;
}

button {
  width: 100px;
  height: 30px;
  margin-bottom: 20px;
}

form a {
  display: block;
  margin-bottom: 10px;
  cursor: pointer;
}

.error {
  font-size: 14px;
  color: red;
  height: 20px;
}

.a {
  text-decoration: none;
  color: rgb(222, 222, 222);
  width: 250px;
  line-height: 100%;
  height: 100%;
}
.Changing {
  width: 500px;
  height: 50px;
  margin: 0 auto;
  display: flex;
  text-align: center;
  /* align-items: center; */
  justify-content: center;
  background-color: rgb(0, 119, 255);
}
.b {
  background-color: rgb(96, 164, 243);
}
</style>

  1. Home.vue

<template>
  <div class="Home">
    <div class="cointer">
      <UserHeader />
      <UserList ref="L" :GetTodo="GetTodo" />
      <UserFooter ref="F" :todos = "todos" :afterClear = "afterClear"></UserFooter>
    </div>
  </div>
</template>

<script>
//引入组件
import UserHeader from "./UserHeader.vue";
import UserFooter from "./UserFooter.vue";
import UserList from "./UserList.vue";
export default {
  name: "Home",
  components: {
    UserHeader,
    UserFooter,
    UserList
  },
  data() {
    return {
      todos:[]
    }
  },
  methods: {
    //获取List中的TODO数据
    GetTodo(value) {
      this.todos = value
      console.log(this.todos);
    },
    afterClear(){
      this.$refs.L.clearAllTodo()
    },
    back(){
      this.$router.push("/Login")
    }
  },
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  color: rgb(95, 95, 95);
}
li,
ul,
ol {
  list-style: none;
}
.cointer {
  width: 600px;
  margin: 0 auto;
}

</style>

Home组件可以自由创新,Home下面还有其他组件,这个可以自由创新
5. 路由

//该文件用于创建整个应用的路由器
import VueRouter from 'vue-router'

//引入组件
import Home from '../components/Home';
import Login from '../pages/Login';
import Register from '../pages/Register'
import Timing from '../components/Timing'

//创建一个路由器
const router = new VueRouter({
    mode:'history',
    routes: [
        {
            path:'',
             redirect:'/Login'
        },
        {
            path: '/Register',
            name:"zhuce",
            component: Register
        },
        {
            path: '/Login',
            name:"denglu",
            component: Login
        },
        {
            path: '/Home',
            name:"zhuye",
            component: Home
        },
        {
            path:'/Timing',
            component:Timing
        }
        
    ]
})

export default router
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值