I
I
Ibishka2020-02-22 16:33:50
Vue.js
Ibishka, 2020-02-22 16:33:50

How to bind @click to router-link?

The function does not work when I bind to router-link.

<router-link to="/" @click="doSomething" ></router-link>


But that's how it works.
<p @click="doSomething" ><p>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2020-02-22
@Ibishka

Purely for information: @click.native="doSomething".
The .native modifier places the click on the component's root element, not on the component itself. But you should n't do
that with a router-link .

O
Oleg Koltunov, 2020-02-22
@i_olega

And won't work.
If you need both a transition and an event, make your own handler, for example

<a @click="handleClick">Click Me</a>

methods: {
    handleClick () {
      console.log('click')
      this.$router.push('/daw')
    }
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question