Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add modifier to v-on in menu activator using Vuetify

Simplified example:

<v-list>
  <v-list-item :to="bla/bla">
    <v-menu>
      <template v-slot:activator="{on}">
        <v-btn v-on.prevent="on"/> // I tried .stop, .stop.prevent, self.prevent, prevent.stop
      </template>
      <div> bla </div>
    <v-menu>   
  </v-list-item>
</v-list>

So as you can see child event v-on triggers v-menu and shows this div. But it also triggers parent :to event. Any ides?

like image 586
Borna Marin Avatar asked Mar 02 '23 01:03

Borna Marin


2 Answers

Try to destruct the on slot prop as follows :

  <template v-slot:activator="{ on: { click } }">
        <v-btn  v-on:click.stop.prevent="click">
          open
          </v-btn>
      </template>
like image 90
Boussadjra Brahim Avatar answered Mar 05 '23 15:03

Boussadjra Brahim


You are using the event modifier on v-on, no on v-on.click.

You can stop the propagation by adding @click with the modifier separately to the button:

<v-btn v-on="on" @click.stop.prevent />

like image 36
Thomas Kuhlmann Avatar answered Mar 05 '23 14:03

Thomas Kuhlmann