Add window event listener – vue.js
Add event on window in vue.js is similar to adding an event with javascript, don’t need to add extra efforts.
syntax with an example:
window.addEventListener('click', this.reloadPage)
With Vue.js
export default { name: 'app', components: { .... }, methods: { reloadPage: function () { {... do your logic ...} } }, created: function () { window.addEventListener('keydown', this.reloadPage) }, destroyed: function () { window.removeEventListener('keydown', this.reloadPage) } }
Thanks!
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Yes21
No5