I am currently utilizing the Vue.js framework and attempting to create a demo. I'm puzzled as to why the addEventListener
function is not running in my code.
This specific issue pertains to a web browser:
_initEvents(el, attr, callback) {
this.$el.querySelectorAll(el).forEach(item => {
if (item.hasAttribute(attr)) {
callback(item, item.getAttribute(attr))
}
})
}
_compile() {
this._initEvents('*', '@click', (item, key) => {
console.log(item)
item.addEventListener('click', ()=> {
console.log('yes')
}, false);
})
}
As observed when I console.log(item)
, the browser console displays
<button @click="test">yes</button>
. Hence, the function does indeed exist, and the button element is present within the DOM.
The perplexing aspect remains: Why is item.addEventListener
failing to execute and display 'yes'?