Advertisement
asimryu

listItem.vue

May 19th, 2021
1,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.20 KB | None | 0 0
  1. <template>
  2.     <ul class="list-group">
  3.         <li class="list-group-item align-middle">
  4.             <input class="form-check-input align-middle me-2" type="checkbox" @change="updateCheck()" v-model="item.completed" aria-label="...">
  5.             <img @click="toggler = !toggler" :src="item.image" alt="" class="image todo-photo align-middle me-2" :class="[item.image ? 'show' : 'hide']">
  6.             <span :class="[item.completed ? 'completed' : 'itemText']"> {{ item.name }} </span>
  7.             <button @click="removeItem()" class="btn btn-danger btn-sm float-end align-middle"><i class="fas fa-trash"></i></button>
  8.             <FsLightbox :toggler="toggler" :sources="[item.image]" />
  9.         </li>
  10.     </ul>
  11.  
  12. </template>
  13. <script>
  14. import FsLightbox from "fslightbox-vue";
  15. export default {
  16.     components: { FsLightbox },
  17.     data() {
  18.         return {
  19.             toggler: false
  20.         }
  21.     },
  22.     props: ['item'],
  23.     methods: {
  24.         updateCheck() {    
  25.             console.log(localStorage.token);   
  26.             let headers = {
  27.                     'headers': {
  28.                         'Content-Type': 'application/json;charset=utf-8',
  29.                         'Accept': 'application/json',
  30.                         'Authorization': 'Bearer ' + localStorage.token                    
  31.                     }
  32.                 };         
  33.             axios.put('api/item/' + this.item.id, {
  34.                 item: this.item
  35.             }, headers)
  36.             .then( response => {
  37.                 if( response.status == 200 ) {
  38.                     this.$emit('itemchanged');
  39.                 }
  40.             })
  41.             .catch( error => {
  42.                 console.log( error );
  43.             } )
  44.         },
  45.         removeItem() {     
  46.             console.log(localStorage.token);
  47.             let headers = {
  48.                     'headers': {
  49.                         'Content-Type': 'application/json;charset=utf-8',
  50.                         'Accept': 'application/json',
  51.                         'Authorization': 'Bearer ' + localStorage.token                    
  52.                     }
  53.                 };
  54.             axios.post('api/item/' + this.item.id, {
  55.                 item: this.item,
  56.                 _method: "DELETE"
  57.             }, headers)
  58.             .then( response => {
  59.                 if( response.status == 200 ) {
  60.                     this.$emit('itemchanged');
  61.                 }
  62.             })
  63.             .catch( error => {
  64.                 console.log( error );
  65.             } )
  66.         }
  67.     }
  68.  
  69. }  
  70. </script>
  71. <style scoped>
  72.     .completed {
  73.         text-decoration: line-through;
  74.         color: #999999;
  75.     }
  76.     .itemText {
  77.         color: #00000;
  78.     }
  79.     .todo-photo {
  80.         border-radius: 50%;
  81.         border: 1px solid #888;
  82.         width: 50px;
  83.         height: 50px;
  84.     }
  85.     .hide { display: none; }
  86.     .show { display: inline; }
  87. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement