欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Vue课堂作业todolist

程序员文章站 2022-03-09 16:09:43
...

用BootStrap框架搭建的页面,这里我先罗列完整的实现代码,注释解析等我做完课堂笔记后补充。

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>BootStrap页面搭建vue实现</title>
    <link
      rel="stylesheet"
      href="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"
    />
  </head>
  <body>
    <div class="container" id="app">
      <div class="panel panel-info">
        <div class="panel-heading">
          <h3 class="panel-title">代办事项</h3>
        </div>
        <div class="pannel-body">
          <input
            type="text"
            class="form-control"
            v-model="txt"
            placeholder="请输入代办事项"
            @keyup="save"
          />

          <ul class="list-group">
            <li class="list-group-item" v-for="todo in todos" :key="todo.id">
              <label for="">
                {{todo.status===0?'【未完成】':'【已完成】'}}{{todo.content}}
                <button
                  type="button"
                  @click="todo.status=1"
                  class="btn btn-info btn-sm"
                  v-show="todo.status==0"
                >
                  完成
                </button>
                <button
                  type="button"
                  @click="delOne(todo)"
                  class="btn btn-danger btn-sm"
                >
                  删除
                </button>
              </label>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <script src="libs/vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          txt: "",
          todos: [],
        },
        methods: {
          save(e) {
            if (e.keyCode === 13) {
              this.todos.push({
                id: Date.now(),
                content: this.txt,
                status: 0,
              });
              this.txt = "";
            }
          },
          delOne(item) {
            this.todos.splice(
              this.todos.findIndex((i) => i.id === item.id),
              1
            );
          },
        },
      });
    </script>
  </body>
</html>

页面效果:
Vue课堂作业todolist