最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - template v-slot inside <v-data-table> is not working in vue 2.0.15 - Stack Overflow

programmeradmin3浏览0评论

i've tried to create a v-data-table including so i can add another field with a button, but it seems that is not working.

Here is the code:

The thing is when i change the package .5.14/vuetify.min.js with to a newest version like this one: .0.15/vuetify.min.js the table ignore the tag.

HTML

  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      class="elevation-1"
    >
      <template v-slot:items="props">
        <td>{{ props.item.name }}</td>
        <td >{{ props.item.calories }}</td>
        <td>{{ props.item.fat }}</td>
        <td><v-btn>Created Button</v-btn></td>
      </template>
    </v-data-table>
  </v-app>
</div>

JS

new Vue({
  el: '#app',
  data () {
    return {
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'left',
          sortable: false,
          value: 'name'
        },
        { text: 'Calories', value: 'calories' },
        { text: 'Fat (g)', value: 'fat' },
        { text: 'Button field', value: 'buttonField' },
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          calories: 159,
          fat: 6.0,
        },
        {
          name: 'Ice cream sandwich',
          calories: 237,
          fat: 9.0,
        },
        {
          name: 'Eclair',
          calories: 262,
          fat: 16.0,
        }
      ]
    }
  }
})

I don't get any error, only the table stops appearing. Could it be a version problem?

i've tried to create a v-data-table including so i can add another field with a button, but it seems that is not working.

Here is the code: https://codepen.io/gerak/pen/yLBpqqG

The thing is when i change the package https://cdnjs.cloudflare./ajax/libs/vuetify/1.5.14/vuetify.min.js with to a newest version like this one: https://cdnjs.cloudflare./ajax/libs/vuetify/2.0.15/vuetify.min.js the table ignore the tag.

HTML

  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      class="elevation-1"
    >
      <template v-slot:items="props">
        <td>{{ props.item.name }}</td>
        <td >{{ props.item.calories }}</td>
        <td>{{ props.item.fat }}</td>
        <td><v-btn>Created Button</v-btn></td>
      </template>
    </v-data-table>
  </v-app>
</div>

JS

new Vue({
  el: '#app',
  data () {
    return {
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'left',
          sortable: false,
          value: 'name'
        },
        { text: 'Calories', value: 'calories' },
        { text: 'Fat (g)', value: 'fat' },
        { text: 'Button field', value: 'buttonField' },
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          calories: 159,
          fat: 6.0,
        },
        {
          name: 'Ice cream sandwich',
          calories: 237,
          fat: 9.0,
        },
        {
          name: 'Eclair',
          calories: 262,
          fat: 16.0,
        }
      ]
    }
  }
})

I don't get any error, only the table stops appearing. Could it be a version problem?

Share Improve this question asked Sep 6, 2019 at 13:51 Gerardo QuirosGerardo Quiros 532 silver badges6 bronze badges 1
  • I see errors in the console if I change your codepen to use 2.0.15 Did you change the css too? Not that it seems to matter. – Xotic750 Commented Sep 6, 2019 at 14:02
Add a ment  | 

1 Answer 1

Reset to default 4

The slots are working differently, you've template per field, to add buttons in a table you can do it like this (https://codepen.io/reijnemans/pen/dybJgjL?editors=1010) :

<div id="app">
  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      class="elevation-1"
    >
      <template v-slot:item.action="{ item }">
        <v-btn>Created Button</v-btn>
      </template>
    </v-data-table>
  </v-app>
</div>

JS:

new Vue({
  el: '#app',
  vuetify: new Vuetify(),

  data () {
    return {
      headers: [
        {
          text: 'Dessert (100g serving)',
          align: 'left',
          sortable: false,
          value: 'name'
        },
        { text: 'Calories', value: 'calories' },
        { text: 'Fat (g)', value: 'fat' },
        { text: 'Actions', value: 'action', sortable: false }
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          calories: 159,
          fat: 6.0,
        },
        {
          name: 'Ice cream sandwich',
          calories: 237,
          fat: 9.0,
        },
        {
          name: 'Eclair',
          calories: 262,
          fat: 16.0,
        }
      ]
    }
  }
})
发布评论

评论列表(0)

  1. 暂无评论