Question:
Why VueJS / Vuetify error rendering a vTable component?

When working with Vue.js and Vuetify to build dynamic and responsive user interfaces, encountering errors in rendering components is not uncommon. The Vue.js framework, along with Vuetify, provides a powerful set of tools for creating web applications, and the integration of various components is a key aspect of this process. One specific scenario that developers may face is the challenge of error rendering when utilizing the vTable component within the Vuetify framework.


Since your template is embedded into the regular page, Vue does not have access to the HTML. Rather, Vue uses the DOM nodes as a template, and the browser will attempt to display the page as usual.

Although browser behavior varies depending on the vendor, in this instance, I believe they all function fairly similarly:

  • The <v-table> element is unknown to the browser, so it simply leaves it alone in the hopes that it will be handled by another application.

  • Upon locating table content elements (<thead>, <tr>, and so on), it anticipates that they will be nestled inside <table> tags; however, <table> is not present. Because of this, the browser eliminates them (along with the v-for).

  • Lastly, Vue inserts <table> tags in place of the <v-table>, but no content remains.

In order to circumvent the problem, transfer the template code to the component via the template property and eliminate it from the HTML page:


const { createApp, computed, ref, reactive } = Vue;

const { createVuetify } = Vuetify;


const vuetify = createVuetify();

const app = createApp({

  template: `

   <p>table below this point</p>

    <v-table>

      <thead>

        <tr>

          <th class="text-left">URL</th>

          <th class="text-left"></th>

        </tr>

      </thead>

      <tbody>

        <tr v-for="item in desserts" :key="item.name">

          <td class="url">{{ item.name }}</td>

          <td class="title">{{ item.calories }}</td>

        </tr>

      </tbody>

    </v-table>

    <p>table over this point</p>

  `,

  setup() {

    const desserts = ref([{

      name: 'Frozen Yogurt',

      calories: 159,

    }, {

      name: 'Ice cream sandwich',

      calories: 237,

    }, {

      name: 'Eclair',

      calories: 262,

    }, {

      name: 'KitKat',

      calories: 518,

    }, ])


    return {

      desserts

    }

  }

});

app.use(vuetify).mount('#app');


<script src="https://cdn.jsdelivr.net/npm/vue@3.3.4/dist/vue.global.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/3.3.19/vuetify.js"></script>

<link href="https://cdn.jsdelivr.net/npm/vuetify@3.3.17/dist/vuetify.min.css" rel="stylesheet">

<link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet">



<div id="app"></div>


Alternatively, you can use <table is="vue:v-table"> instead of using <v-table> directly:

const { createApp, computed, ref, reactive } = Vue;

const { createVuetify } = Vuetify;


const vuetify = createVuetify();

const app = createApp({

  setup() {

    const desserts = ref([{

      name: 'Frozen Yogurt',

      calories: 159,

    }, {

      name: 'Ice cream sandwich',

      calories: 237,

    }, {

      name: 'Eclair',

      calories: 262,

    }, {

      name: 'KitKat',

      calories: 518,

    }, ])


    return {

      desserts

    }

  }

});

app.use(vuetify).mount('#app');


<script src="https://cdn.jsdelivr.net/npm/vue@3.3.4/dist/vue.global.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/3.3.19/vuetify.js"></script>

<link href="https://cdn.jsdelivr.net/npm/vuetify@3.3.17/dist/vuetify.min.css" rel="stylesheet">

<link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet">



<div id="app">

  <p>table below this point</p>

    <table is="vue:v-table">

      <thead>

        <tr>

          <th class="text-left">URL</th>

          <th class="text-left"></th>

        </tr>

      </thead>

      <tbody>

        <tr v-for="item in desserts" :key="item.name">

          <td class="url">{{ item.name }}</td>

          <td class="title">{{ item.calories }}</td>

        </tr>

      </tbody>

    </table>

    <p>table over this point</p>

</div>


Suggested blogs:

>How to create a One Page App with Angular.js, Node.js and MongoDB?

>How to Create an array based on two other arrays in Php

>How To Create Nested Table Structure In Angular?

>How to Set up the local environment for Angular development?

>How to solve encoding issue when writing to a text file, with Python?

>Step by Step guide to Deploy Terraform in Azure using GitHub Actions

>Testing react components using Hooks and Mocks


Ritu Singh

Ritu Singh

Submit
0 Answers