[Vuejs]-Socket.io and vue.js fetching data

3👍

Try changing you fetchData function to this:

fetchData: function () {
    socket.emit('getAllSongs')
    var that = this;
    socket.on('allSongs',function(data) {
        that.songs = data
    });
}

The reason is the value this is different in the callback context and is not the component object which you expect it to be.

0👍

I think you need to bind this to the end of your function or to use ES6 arrow syntax =>

socket.on('allSongs',function(data) {
    that.songs = data
}.bind(this));

socket.on('allSongs',data => {
    that.songs = data
});
👤Wissa

Leave a comment