Detailed explanation of Vue's TodoList case

Detailed explanation of Vue's TodoList case

insert image description here

insert image description here

<template>
  <div id="root">
    <div class="todo-container">
      <div class="todo-wrap">
        <Top :received="received" />
        <List :todos="todos" :checkTodo="checkTodo" :deleteTodo="deleteTodo" />
        <Bottom :todos="todos" :checkAllTodo="checkAllTodo" :clearAllTodo="clearAllTodo" />
      </div>
    </div>
  </div>
</template>
<script>
  import Top from './components/Top.vue'
  import Bottom from './components/Bottom.vue'
  import List from './components/List.vue'
  export default {
    name: 'App',
    components:
      Top,
      List,
      Bottom
    },
    data() {
      return {
        todos: [{
            id: '001',
            title: 'Eating',
            done: true
          },
          {
            id: '002',
            title: 'Sleep',
            done: false
          },
          {
            id: '003',
            title: 'Playing Beans',
            done: false
          },
        ]
      }
    },
    methods: {
      //Add a todo
      received(todoObj) {
        this.todos.unshift(todoObj);
      },
      //Uncheck todo
      checkTodo(id) {
        this.todos.forEach((todo) => {
          //Function bodyif (todo.id === id) todo.done = !todo.done;
        })
      },
      //deleteTodo(id) {
        this.todos = this.todos.filter(todo => todo.id !== id)
      },
      //Select all or deselect all checkAllTodo(done) {
        this.todos.forEach((todo) => {
          todo.done = done
        })
      },
      // Clear all completed data clearAllTodo() {
        this.todos = this.todos.filter((todo) => {
          return !todo.done
        })
      }
    }
  }
</script>
<style lang="css">
  /*base*/
  body {
    background: #fff;
  }
  .btn {
    display: inline-block;
    padding: 4px 12px;
    margin-bottom: 0;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
    border-radius: 4px;
  }
  .btn-danger {
    color: #fff;
    background-color: #da4f49;
    border: 1px solid #bd362f;
  }
  .btn-danger:hover {
    color: #fff;
    background-color: #bd362f;
  }
  .btn:focus {
    outline: none;
  }
  .todo-container {
    width: 600px;
    margin: 0 auto;
  }
  .todo-container .todo-wrap {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
  }
</style>

Summarize

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Vue encapsulates a TodoList example and implements the application of browser local cache
  • Detailed explanation of the simple todolist example of vuex
  • Vue learns parent-child component communication from TodoList
  • Vuejs implements simple todoList function and component example code
  • vue.js example todoList project

<<:  Detailed explanation of flex layout in CSS

>>:  Summary of several principles that should be followed in HTML page output

Recommend

Vue implements weather forecast function

This article shares the specific code of Vue to r...

Example of implementing QR code scanning effects with CSS3

Online Preview https://jsrun.pro/AafKp/ First loo...

Implementation of nginx flow control and access control

nginx traffic control Rate-limiting is a very use...

10 bad habits to avoid in Docker container applications

There is no doubt that containers have become an ...

How to set the width and height of html table cells

When making web pages, you often encounter the pr...

A friendly alternative to find in Linux (fd command)

The fd command provides a simple and straightforw...

Analysis of the principle of Rabbitmq heartbea heartbeat detection mechanism

Preface When using RabbitMQ, if there is no traff...

Public free STUN servers

Public free STUN servers When the SIP terminal us...

Add unlimited fonts to your website with Google Web Fonts

For a long time, website development was hampered...

Detailed explanation of the initialization mechanism in bash

Bash Initialization Files Interactive login shell...

Detailed explanation of MySQL database transaction isolation levels

Database transaction isolation level There are 4 ...

Common ways to optimize Docker image size

The Docker images we usually build are usually la...