<h2 id="header">Home Page</h2>
> Using addEventListener and removeEventListener
mounted() {
this.$refs['header'].addEventListener('click', (e) => {
// Do stuff
}
},
beforeDestroy() {
this.$refs['header'].removeEventListener('click'), (e) => {
// Do stuff
}
}
> Using nextTick if the element is still undefined with the code but inserted into the DOM
mounted() {
this.$nextTick(function() {
this.$refs['header'].addEventListener('click', (e) => {
// Do stuff
}
});
},