Guest User

Untitled

a guest
Feb 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <div id="app">
  2. <h1>{{ message }}</h1>
  3. <form v-on:submit.prevent="addNewTodo">
  4. <input type="text" v-model="todo.task">
  5. <button type="submit">Add todo</button>
  6. </form>
  7.  
  8. <ul>
  9. <li v-for="todo in todos" :class="{ completed: todo.isActive }" @click="$set(todo, 'isActive', !todo.isActive)">
  10. {{ todo.task }} <span v-on:click="deleteTodo">{{ todo.delete }}</span>
  11. </li>
  12. </ul>
  13. </div>
  14.  
  15. var app = new Vue({
  16. el: '#app',
  17. data: {
  18. message: 'List of things to do today',
  19. todos: [
  20. { task: 'Have breakfast', delete:'(x)'},
  21. { task: 'Go to the gym', delete:'(x)'},
  22. { task: 'Study Vuejs', delete:'(x)'}
  23. ],
  24. todo: {task: '', delete: '(x)'}
  25. },
  26. methods: {
  27. addNewTodo: function(){
  28. this.todos.push( this.todo );
  29. },
  30. deleteTodo: function(){
  31. this.todos.shift( this.todo )
  32. },
  33. }
  34. });
Add Comment
Please, Sign In to add comment