Advertisement
majweb

Untitled

Jul 11th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Component: Plan.vue
  2.  
  3. <template>
  4.     <div>
  5.         <div class="col-xs-12 col-md-6">
  6.             <div class="bg-blue text-center" style="padding: 5px;font-weight: bold;">
  7.                 <div v-if="index === '1'">
  8.                     Poniedziałek
  9.                 </div>
  10.                 <div v-else-if="index === '2'">
  11.                     Wtorek
  12.                 </div>
  13.                 <div v-else-if="index === '3'">
  14.                     Środa
  15.                 </div>
  16.                 <div v-else-if="index === '4'">
  17.                     Czwartek
  18.                 </div>
  19.                 <div v-else-if="index === '5'">
  20.                     Piątek
  21.                 </div>
  22.                 <div v-else-if="index === '6'">
  23.                     Sobota
  24.                 </div>
  25.                 <div v-else-if="index === '7'">
  26.                     Niedziela
  27.                 </div>
  28.             </div>
  29.             <div class="row">
  30.                 <div class="col-xs-12">
  31.                     <table class="table">
  32.                         <thead>
  33.                         <tr class="info">
  34.                             <th>
  35.                                 <small>Część ciała</small></th>
  36.                             <th>
  37.                                 <small>Ćwiczenie</small></th>
  38.                             <th>
  39.                                 <small>Serie</small></th>
  40.                             <th>
  41.                                 <small>Powtózenia</small></th>
  42.                             <th>
  43.                                 <small>Ciężar</small></th>
  44.                             <th>
  45.                                 <small>Czas</small></th>
  46.                             <th></th>
  47.                         </tr>
  48.                         </thead>
  49.                         <tbody>
  50.                         <tr v-for="ones in plan">
  51.                             <td>{{ones.part.name}}</td>
  52.                             <td>{{ones.exercise.type}}</td>
  53.                             <td>{{ones.series}}</td>
  54.                             <td>{{ones.repeat}}</td>
  55.                             <td>{{ones.weight}}</td>
  56.                             <td>{{ones.time}}</td>
  57.                             {{ones.id}}
  58.                             <td><a class="btn btn-danger btn-xs" style="margin-left: 5px;" @click="$emit('delete-plan')">
  59.                                 <i class="fa fa-times" aria-hidden="true"></i>
  60.                             </a></td>
  61.                         </tr>
  62.                         </tbody>
  63.                     </table>
  64.                 </div>
  65.             </div>
  66.         </div>
  67.     </div>
  68. </template>
  69.  
  70. <script>
  71.     export default {
  72.         props:['plan','index']
  73.     }
  74. </script>
  75. Component: Plans.vue
  76.  
  77. <template>
  78.    <div class="row">
  79.        <single-plan v-for="(plan,index) in plans" :index="index" :plan="plan" @delete-plan="deletePlans"></single-plan>
  80.    </div>
  81. </template>
  82.  
  83. <script>
  84.     import Plan from './Plan.vue'
  85.     export default {
  86.         created() {
  87.             this.giveit();
  88.         },
  89.         data () {
  90.             return {
  91.                 plans:[]
  92.             };
  93.         },
  94.         components:{
  95.             'single-plan' : Plan
  96.         },
  97.         methods: {
  98.         giveit(){
  99.                   axios.get('/klient/test')
  100.                       .then( (response) => {
  101.                         this.plans = response.data.plans;
  102.                         console.log(response);
  103.                 })
  104.                       .catch(function (error) {
  105.                           console.log(error);
  106.                       });
  107.                 },
  108.             deletePlans(plan) {
  109.                 axios.delete('/klient/planyajax/'+plan.id)
  110.                         .then(response=>{
  111.                             let index = this.plans.indexOf(plan);
  112.                             this.plans.splice(index,1);
  113.             }
  114.         }
  115.     }
  116. </script>
  117. Why $emit not delete data? why deletePlans(plan) gives me all plan not only clicked?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement