zarkoboyadjiev

Untitled

Mar 21st, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <template>
  2. <div id="app">
  3. <Header />
  4. <AddTodo v-on:add-todo="addTodo"/>
  5. <Todos v-bind:todos="todos" v-on:del-todo="deleteTask"/>
  6. <!-- From file Todos // todos is from data() -->
  7.  
  8. </div>
  9. </template>
  10.  
  11. <script>
  12. /* eslint-disable */
  13. //import HelloWorld from './components/HelloWorld.vue'
  14. import Todos from './components/Todos.vue';
  15. import Header from './components/Header.vue';
  16. import AddTodo from './components/AddTodo.vue';
  17. import axios from 'axios';
  18.  
  19. export default {
  20. name: 'App',
  21. //------------------------start components ------------------------
  22. components: {
  23. //child
  24. Todos,
  25. Header,
  26. AddTodo
  27. },
  28. //------------------------end components ------------------------
  29. //------------------------start data ------------------------
  30. data(){
  31. return {
  32. todos:[]
  33. }
  34. },
  35. //------------------------end data ------------------------
  36. //------------------------start methods ------------------------
  37. methods:{
  38. deleteTask(id){
  39. this.todos = this.todos.filter(todo => todo.id !== id);
  40. },
  41. addTodo(newTodo){
  42. //const {title,completed}
  43. this.todos = [...this.todos , newTodo];
  44. },
  45. created(){
  46. axios.get('https://jsonplaceholder.typicode.com/todos?_limit=5')
  47. .then(res=>this.todos = res.data)
  48. .catch(err=>console.log(err));
  49. }
  50. }
  51. }
  52. </script>
  53.  
  54. <style>
  55. * {
  56. box-sizing: border-box;
  57. margin: 0;
  58. padding: 0;
  59. }
  60. body {
  61. font-family: Arial, Helvetica, sans-serif;
  62. line-height: 1.4;
  63. }
  64. .btn {
  65. display: inline-block;
  66. border: none;
  67. background: #555;
  68. color: #fff;
  69. padding: 7px 20px;
  70. cursor: pointer;
  71. }
  72. .btn:hover {
  73. background: #666;
  74. }
  75. </style>
Advertisement
Add Comment
Please, Sign In to add comment