1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <style src="todomvc-app-css/index.css"></style>
- <template>
- <section class="todoapp">
- <!-- header -->
- <header class="header">
- <h1>todos</h1>
- <input class="new-todo"
- autofocus
- autocomplete="off"
- placeholder="What needs to be done?"
- @keyup.enter="addTodo">
- </header>
- <!-- main section -->
- <section class="main" v-show="todos.length">
- <input class="toggle-all"
- type="checkbox"
- :checked="allChecked"
- @change="toggleAll(!allChecked)">
- <ul class="todo-list">
- <todo v-for="todo in filteredTodos" :todo="todo"></todo>
- </ul>
- </section>
- <!-- footer -->
- <footer class="footer" v-show="todos.length">
- <span class="todo-count">
- <strong>{{ remaining }}</strong>
- {{ remaining | pluralize 'item' }} left
- </span>
- <ul class="filters">
- <li v-for="(key, val) in filters">
- <a href="#/{{$key}}"
- :class="{ selected: visibility === key }"
- @click="visibility = key">
- {{ key | capitalize }}
- </a>
- </li>
- </ul>
- <button class="clear-completed"
- v-show="todos.length > remaining"
- @click="clearCompleted">
- Clear completed
- </button>
- </footer>
- </section>
- </template>
- <script>
- import Todo from './Todo.vue'
- const filters = {
- all: (todos) => todos,
- active: (todos) => todos.filter(todo => !todo.done),
- completed: (todos) => todos.filter(todo => todo.done)
- }
- export default {
- components: { Todo },
- data () {
- return {
- visibility: 'all',
- filters: filters
- }
- },
- computed: {
- todos () {
- return this.$store.state.todos
- },
- allChecked () {
- return this.todos.every(todo => todo.done)
- },
- filteredTodos () {
- return filters[this.visibility](this.todos)
- },
- remaining () {
- return this.todos.filter(todo => !todo.done).length
- }
- },
- methods: {
- addTodo (e) {
- var text = e.target.value
- if (text.trim()) {
- this.$store.actions.addTodo(text)
- }
- e.target.value = ''
- },
- toggleAll () {
- this.$store.actions.toggleAll()
- },
- clearCompleted () {
- this.$store.actions.clearCompleted()
- }
- }
- }
- </script>
|