[Vuejs]-Vue 1 class binding returning always false

0👍

Ok, I made it work by adding a default variable in data and changing it later:

data: {
    ...
    userStatus: {},
}

And in the method. As you can see I made some irrelevant changes on the Controller side.

methods: {
    getUserStatus: function(userid)
    {
        var userStatus = this.$http.post(base_url + 'api/v1/status/' + userid).then(function(response) {
            this.userStatus = JSON.parse(response.data);
        });

        return this.userStatus.status;
    },
    ...
}

And in the HTML side I use:

<h4 class="media-heading">
    @{{ conversation.user.name }}
    <i class="status connected" v-bind:class="[ 'status', getUserStatus(conversation.user.id) ? 'connected' : 'disconnected' ]"></i>
</h4>

Now I have a different issue: The function seems to run repeteadly so the status are constantly changing. All the other functions runs once.

Leave a comment