Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Demers94's avatar

VueJS component for table row

Hi,

I'm trying to use a custom component for a table row, but I can't get it to display. I'm using Laravel with the component in its own Vue file. Here's the code where the component is used :

<table class="table">
    @foreach($articles as $article)
        <tr is="blog-article" :article="{{ $article }}"></tr>           
    @endforeach
</table>

Here is where the component is registered (inside of app.js) :

Vue.component('blog-article', require('./components/Article.vue'));

And here is the component itself :

<template>
 <tr>
        <td>{{ article.title }}</td>
         <td>{{ article.published_at }}</td>
         <td>
             <button class="btn btn-sm btn-default">Désactiver</button>
                <a href="/blog/gerer/{{ article.slug }}" class="btn btn-sm btn-         default">Modifier</a>
                <button class="btn btn-sm btn-danger">Supprimer</button>
            </td>
    </tr>
</template>

<script>
 export default {
         mounted() {
        
         },

        props: ['article'],
 }
</script>

I can see the component in the Vue devtools :

But the table rows are not displayed :

I'm thinking that there's something wrong with the way I'm using the component in my blade file, but according to the Vue documentation that's what you need to do for some HTML elements like <tr>, I can't simply do <blog-article>.

What am I doing wrong?

Thanks for the help!

0 likes
3 replies
willvincent's avatar

what are you seeing in the markup as a result of this:

<tr is="blog-article" :article="{{ $article }}"></tr>

You may need to json_encode($article) to dump it inline like that..

willvincent's avatar

But really.. what are you gaining by using vue here at all?

Demers94's avatar

Nothing, no elements are being rendered at all.

You may need to json_encode($article) to dump it inline like that..

It doesn't change anything, if I do a console.log() of the article from within the component's mounted() method, I will see the article.

But really.. what are you gaining by using vue here at all?

I haven't gotten there yet but the buttons in the last row will make some AJAX requests when clicked. I'd rather have a Vue component than creating a new instance, and even though in this case I could get away without using components, I'd like to figure this out because I'll run in this issue again sooner or later. :P

Please or to participate in this conversation.