Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1.  
  2. Vue.component('todo-item', {
  3. template: `\
  4. <li>\
  5. {{ title }}\
  6. <span>Priority:\
  7. <select>\
  8. <option v-for="option in options" v-bind:value="option" :selected="$root.checkIfSelectMatchesTodo(option, id)"> {{ option }} </option>\
  9. </select></span>\
  10. <button v-on:click="$emit(\'remove\')">X</button>\
  11. </li>\
  12. `,
  13. props: ['title', 'options', 'id']
  14. });
  15.  
  16. const todoApp = new Vue({
  17. el: '#todoApp',
  18. data: {
  19. newTodoText: '',
  20. todos: [
  21. {
  22. id: 1,
  23. title: 'Do the dishes'
  24. }, {
  25. id: 2,
  26. title: 'Take out the trash'
  27. }, {
  28. id: 3,
  29. title: 'Mow the lawn'
  30. }
  31. ],
  32. nextTodoId: 4,
  33. options: [1, 2, 3]
  34. },
  35. methods: {
  36. addNewTodo: function(){
  37. this.options.push(this.nextTodoId);
  38. this.todos.push({
  39. id: this.nextTodoId++,
  40. title: this.newTodoText
  41. });
  42. this.newTodoText = '';
  43. },
  44. removeTodo: function(index){
  45. this.options.pop();
  46. this.nextTodoId--;
  47. this.todos.splice(index, 1);
  48. this.todos.forEach((todo, index) => {
  49. todo.id = index + 1;
  50. })
  51. },
  52. checkIfSelectMatchesTodo(option, id){
  53. return option === id ? true : false;
  54. }
  55. }
  56. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement