I'm new to vue.js and here is my problem:
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); // <--Problem here
}
});
},
But I get this error in the browser console:
Uncaught TypeError: self.usersList.push is not a function
I've also tryied a fixed string instead of msg.Name but get the same error.
What's wrong here and how to fix it?
usersList: ''in data, change it tousersList: [].