Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css"> -->
  9. <style>
  10.  
  11. .done {
  12. text-decoration: line-through;
  13. color: grey;
  14. }
  15.  
  16.  
  17. </style>
  18. </head>
  19. <body>
  20.  
  21. <div id="root" >
  22.  
  23. Firstname: <input type="text" v-model="firstname"/>
  24. <button @click="addName">Add to list</button>
  25. <button @click="pocetni">Load</button>
  26. <button @click="remove">Remove all</button>
  27.  
  28. <br/>
  29. <ul>
  30. <name-component :name='name' v-for="name, index in names" :class="{'done':name.completed}" >
  31. {{name.ime}}
  32. <button @click="finish(index)" >Finished</button>
  33. <button @click="removeAtIndex(index)">Remove at index</button>
  34.  
  35. </name-component>
  36. </ul>
  37. <button @click="removeAllDone">Remove all done</button>
  38. <p> {{numberNames}}</p>
  39. </div>
  40.  
  41. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  42. <!-- <script src="main.js"></script> -->
  43. <script>
  44.  
  45. Vue.component('name-component',{
  46. data(){
  47. return{
  48. isEditing: false
  49. }
  50. },
  51. props:['name'],
  52. template:`
  53. <div>
  54. <li v-show="!isEditing">
  55. <slot></slot>
  56. <button @click="clicked">Edit</button>
  57. </li>
  58. <div v-show="isEditing">
  59. <input v-model="name.ime" />
  60. <button @click="saved">Save edit</button>
  61. </div>
  62. </div>
  63. `,
  64. methods: {
  65. clicked(){
  66.  
  67. this.isEditing = true;
  68. },
  69. saved(){
  70. this.isEditing = false;
  71. },
  72.  
  73.  
  74. }
  75.  
  76. });
  77.  
  78. new Vue({
  79. el:'#root',
  80. data:{
  81. firstname:"",
  82. names:[
  83. {ime:'Buzo',completed:false},
  84. {ime:'Rahmanjinov', completed:true}
  85. ],
  86.  
  87. },
  88. methods:{
  89. addName(){
  90. var newName = this.firstname.trim();
  91. if(!newName){return;}
  92. this.names.push(
  93. {ime: newName, completed:false}
  94. );
  95. this.firstname = ""
  96. },
  97. pocetni(){
  98. this.names = [
  99. {ime:'Buzo', completed:false},
  100. {ime:'Rahmanjinov', completed:true}
  101. ];
  102. },
  103. remove(){
  104. this.names = [];
  105. },
  106. finish(index){
  107. if(this.names[index].completed == false){
  108. this.names[index].completed = true;
  109. }
  110. else if(this.names[index].completed == true){
  111. this.names[index].completed = false;
  112. }
  113. },
  114. removeAtIndex(index){
  115. this.names.splice(index,1);
  116. },
  117.  
  118. removeAllDone(){
  119. let duzina = this.names.length;
  120. for(var i = 0;i<this.names.length;i++){
  121. if(this.names[i].completed == true){
  122. this.names.splice(i,1);
  123. --i;
  124. }
  125. }
  126. }
  127.  
  128. },
  129. computed:{
  130. numberNames(){
  131. return this.names.length;
  132. }
  133. }
  134.  
  135. });
  136. </script>
  137.  
  138. </body>
  139. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement