N
N
Nikolai Chuprik2018-02-16 19:40:04
Vue.js
Nikolai Chuprik, 2018-02-16 19:40:04

How to get the global context inside v-on = "..."?

Here's roughly what I need:

@click = "myVueMeth1(); myVueMeth2(); document.forms[0].submit()"

But it doesn't work. I understand that this is possible:
onclick = "vm.myVueMeth1(); vm.myVueMeth2(); document.forms[0].submit()"

where vm is a Vue object
But I want to keep the style clean.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-02-16
@choupa

Make a separate method:

methods: {
  onClick() {
    this.myVueMeth1();
    this.myVueMeth2();
    document.forms[0].submit();
  },
},

UPD. Of course, you can define a computed property on document like this:
computed: {
  document() {
    return document;
  },
},

Then your first example will work. But it's kind of barbaric, in my opinion.

E
evilray, 2018-02-16
@evilray

If you need a global context in v-on, then you are not properly preparing vue.
If you tell about the problem in more detail, it will be possible to answer in more detail how to correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question