我做了一张桌子,每个tbody项都是这样的组件:

<div class="panel">
    <table class="table">
    <thead>
        <tr>
            <th>Door</th>
            <th>Van</th>
            <th>Naar</th>
            <th>Type</th>
            <th>Datum</th>
        </tr>
    </thead>
    <tbody>
       <ride v-for="ride in rides" :ride="ride"></ride>
    </tbody>
  </table>
</div>

游乐设施:
<template>
<show-ride-modal :ride="ride"></show-ride-modal>
<tr>
    <td>{{ ride.user.name }}</td>
    <td>{{ ride.location.from }}</td>
    <td>{{ ride.location.to }}</td>
    <td>{{ ride.type.name }}</td>
    <td>{{ ride.date }}</td>
    <td>
        <a @click="show" class="btn-show">Bekijk</a>
        <a v-link="{ name: 'ritten' }" class="btn-edit">Bewerk</a>
        <a v-link="{ name: 'ritten' }" class="btn-delete">Verwijder</a></td>
</tr>
</template>

所以我希望它看起来像这样:

html - Vue.js表组件不起作用-LMLPHP

但它看起来像这样:

html - Vue.js表组件不起作用-LMLPHP

我怎样才能解决这个问题?

最佳答案

杰米

如果您尚未解决问题,请查看下一个代码段。我没有使用所有的数据/模式布局等,而只是一个小例子来使表格正确呈现。我想添加小的修改作为对卡特答案的评论,但是mny的声誉还不够高。

卡特答案的唯一变化是:
代替在tbody中的tr上重复,在vbody中添加v-for。



var ride = Vue.extend({
  props: ['ride'],
  template: `<tr>
              <td>{{ ride.user.name }}</td>
              <td>{{ ride.location.from }}</td>
              <td>{{ ride.location.to }}</td>
              <td>{{ ride.type.name }}</td>
              <td>{{ ride.date }}</td>
              <td><a @click="show" class="btn-show">Bekijk</a></td>
              <td><a v-link="{ name: 'ritten' }" class="btn-edit">Bewerk</a></td>
              <td><a v-link="{ name: 'ritten' }" class="btn-delete">Verwijder</a></td>
            </tr>`
})

Vue.component('ride', ride)

new Vue({
  el: 'app',
  data: function () {
    return {
      rides: [
        {
          user: {
            name: 'Jaimy'
          },
          location: {
            from: 'Van',
            to: 'Naar'
          },
          type: {
            name: 'Type'
          },
          date: 'datum'
        },
        {
          user: {
            name: 'Jaimy 2'
          },
          location: {
            from: 'Van 2',
            to: 'Naar 2'
          },
          type: {
            name: 'Type 2'
          },
          date: 'datum 2'
        }
      ]
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<app>
<div class="panel">
    <table class="table">
    <thead>
        <tr>
            <th>Door</th>
            <th>Van</th>
            <th>Naar</th>
            <th>Type</th>
            <th>Datum</th>
            <th></th>
            <th></th>
            <th></th>
        </tr>
    </thead>
    <tbody v-for="ride in rides" is="ride" :ride="ride">
    </tbody>
  </table>
</div>
</app>

关于html - Vue.js表组件不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38760742/

10-12 00:07
查看更多