Recently starting with vue.js and facing an issue:
data: {
ws: null,
newMsg: '',
username: null,
usersList: ''
},
created: function() {
var self = this;
this.ws = new WebSocket('ws://' + window.location.host + '/room');
this.ws.addEventListener('message', function(e) {
var msg = JSON.parse(e.data);
if (msg.Message == "joined" ) {
self.usersList.push(msg.Name); // <--Issue persists here
}
});
},
However, encountering an error displayed in the browser console:
Uncaught TypeError: self.usersList.push is not a function
Even after trying to use a static string instead of msg.Name
, the error remains the same.
What could be the problem here and how can it be resolved?