Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
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:

Free download pdf