Advanced Vue.js - Directives, Plugins, and Render Functions Chapter 17
appendToChat (text) {
this.chat += text + 'n'
}
}
}
We factored out the appendToChat method because we will use it to append all the
messages we'll receive. To do this, we must wait for the component to be instantiated. The
created hook is a safe place for that:
...
created () {
ws.onmessage = event => {
this.appendToChat(event.data)
}
}
...
Now launch the application to chat with your personal echo chamber: