最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add modifier to v-on in menu activator using Vuetify - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Nov 30, 2021 at 19:46 Boussadjra Brahim 1 asked Sep 18, 2020 at 11:48 Borna MarinBorna Marin 1137 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 6

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>

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 />

发布评论

评论列表(0)

  1. 暂无评论