export default {
name: 'App',
data(){
return {
messages: [],
newMessage: null,
connection: null
};
},
created: function() {
this.connection = new WebSocket("ws://127.0.0.1:8000/ws/chat/")
this.connection.onmessage = function(event) {
let receivedMessage = JSON.parse(event.data).message;
this.receiveMessage(receivedMessage)
}
this.connection.onopen = function(event) {
return event
}
},
methods: {
sendMessage: function () {
this.connection.send('{"message":"'+this.newMessage+'"}');
},
receiveMessage(message) {
this.messages.push(message)
}
}
}
Error:
this.receiveMessage is not a function