Home  >  Q&A  >  body text

Vue JS - <tr>, <td> elements not rendering when passed to table component

I have registered a file table component using vue.js:

<template>
        <div>
            <table class="table border">
                <thead>
                    <tr>
                        <td>header 1</td>
                        <td>header 2</td>
                    </tr>
                </thead>
                <tbody>
                    <slot></slot>
                </tbody>
            </table>
        </div>
    </template>
    
    <script>
    export default {};
    </script>
    <style></style>

I want to use it as a representation component. When I try to pass tr and td elements to it in Laravel Blade like this:

<table-component>
                <tr>
                    <td>2</td>
                    <td>2</td>
                    <td>2</td>
                    <td>2</td>
                </tr>
</table-component>

How do I register a component:

Vue.component(
    "table-component",
    require("./components/admin/TableComponent.vue").default
);

Everything except rows and data elements will be rendered, and the table will become irregular. This is the table content and elements after rendering in the browser:

Table elements in browser images

I read online articles and searched via Q/As but didn't find anything.

P粉449281068P粉449281068164 days ago495

reply all(1)I'll reply

  • P粉501007768

    P粉5010077682024-03-28 12:50:41

    It is mentioned in the official documentation DOM template parsing precautions

    For more clarity, see also this issue https://github.com/vuejs/Discussion/issue/204

    reply
    0
  • Cancelreply