简体   繁体   中英

Vue JS Load dynamic Data issue with Modal

This is my table Data

 <tr v-for="company, index in companies.data" :key="index.id">
                <td>{{ company.first_name }} {{ company.last_name }}</td>
                <td>{{ company.license_no }}</td>
                <td>{{ company.car_registration }}</td>
                <td>
                <button id="show-modal"  @click="modalOpen(0)" class="view-button">Call</button>
                 <modal v-model="compnay" v-if="showModal" @close="showModal = false">
                        <h3 slot="header" style="margin-left: auto;
    margin-right: auto;">{{company.first_name}} {{ company.last_name }}</h3>
                        <h3 slot="body">Car Registration No: {{company.car_registration}}</h3>                        
                    </modal>
                </td>
              </tr>

I have passed the dynamic data to modal slots it is showing the same every time i click on different item In my API i have different data & also in my table is showing different data but in modal loading same data. This is Modal Content

<script type="text/x-template" id="modal-template">
  <transition name="modal">
    <div class="modal-mask">
      <div class="modal-wrapper">
        <div class="modal-container">
          <div class="modal-header">
            <slot name="header" style="margin-left: auto;margin-right: auto;">         
            </slot>
          </div>
          <div class="modal-body" id="el">
            <slot name="body">
            </slot>
            <slot name="test">
             Calling  @{{modalcompany}}

            </slot>
          </div>

          <div class="modal-footer">
            <slot name="footer">

              <button class="modal-default-button view-button" @click="$emit('close')">
                OK
              </button>
            </slot>
          </div>
        </div>
      </div>
    </div>
  </transition>
</script>

Modal Content

Here's a quick solution from my guess to solve your problem, I hope it helps!

<div id="app">
  <div v-for="company in companies">
    <div class="company">
      {{ company.name }} - <button @click="openModal(company)"> View appointments</button>
    </div>
  </div>
  <modal v-model="showModal" company="company">
    <div slot="header">{{company.name}}</div>
    <div slot="body">{{(company.appointments || []).join(', ')}}</div>
  </modal>
</div>

You can see the full demo here: https://codepen.io/chainlist/pen/qMjBOQ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM