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

JoerJoers's avatar

Vue JS - Displaying List: Check if the object in the List is Null

Any suggestions on how to check if the object in the list is null or empty? See example below.

Array Structure

array:2 [▼
  0 => array:4 [▼
    "id" => 1
    "title" => "Notice of Award (Email)"
    "remarks" => "Sample Description"
    "document" => "confirmation.email"
  ]
  1 => array:4 [▼
    "id" => 2
    "title" => "Assignment Order (AO)"
    "remarks" => null
    "document" => null
  ]

Vue - AJAX Get Request

ready: function() {
        this.fetchRequirements();
    },

methods: {
fetchRequirements: function() {
        var url = '/api/project/' + this.projectSlug + '/requirements';
            this.$http.get(url, function(data) {
                this.$set('requirements', data)
            });

        }
}

View

<tr v-repeat="requirements">
    <td>@{ id }</td>
    <td>@{ title }</td>
    <td>@{ remarks }</td>
    <td>@{ document }</td>
</tr>

Note: Those are double curly braces.

This is working correctly but I just want to check
IF document object is null i will display a button
ELSE display normal @{ document }

Any suggestion on how to implement this? :)

Thanks in advance! :)

0 likes
2 replies
xdimension's avatar
Level 5

Maybe you can use v-if directive like this:

<td v-if="document">@{ document }</td>
<td v-if="!document"><button></td>
a.ankitpatel's avatar

You can also check length of object,

<td v-if="Object.keys(document).length">@{document}</td>
<td v-else><button><td>

Please or to participate in this conversation.