How to use Addeventlistener() in vueJs

Asked

Viewed 360 times

0

I’m doing a function of my project and need to use the event addEventListener() but you’re making a mistake:

excluirVariante:function(v){
    console.log(this.$el.querySelector('#op_nao'));
    console.log(this.$el.querySelector('#op_sim'));
    $('#model_permissao').modal('show');
    console.log(v);
    this.$el.querySelector("#op_sim").addEventListener("click",function(){
        this.lista_variante.find(function(el,i,list){
            if(el===v){
                list.splice(i,1);
                console.log('foi');
            }
        });
    },false);
    this.$el.querySelector('#op_nao').addEventListener('click',function(){
        $('#model_permissao').model('hide');
    },false);
},


That is the mistake:

app.js:14719 Uncaught Typeerror: Cannot read Property 'addeventlistener' of null At Vuecomponent.excluirVariante (app.js:14719) At Proxy.boundFn (app.js:27396) at click (app.js:18030) At Htmlelement.Invoker (app.js:28969)

  • The deleterVariante function is executed when clicked on a button?

  • 2

    You are trying to assign an event to an element that does not exist, at least one of your querySelector is returning null. Besides, it’s strange the way you’re doing things, in Vue.js you rarely need to manually manipulate the DOM in this way.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.