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

javascript - While using Bootstrap-Vue, how do you prevent a b-dropdown from closing when clicking on a nested b-input component

programmeradmin0浏览0评论

I'm pretty sure I just don't understand how to implement Vue's Event Modifiers. According to that documentation, all I have to do is add this:

<!-- the click event's propagation will be stopped -->
<a v-on:click.stop="doThis"></a>

Here's how I interpreted the example into my pug code:

b-dropdown(text="Actions")
  b-dropdown-item
    b-form(inline)
      .row
        .col
          b-input(@click.stop='' placeholder="#123")
          b-button(:href='printCheck' variant="primary") Print Check

It looks pretty simple, however it's not working as expected. If you need more supporting info, just ask. And feel free to tweak the title; I wasn't sure if my question is a vue, bootstrap-vue, or javascript question.

Thanks for your time in advance,
Kevin

I'm pretty sure I just don't understand how to implement Vue's Event Modifiers. According to that documentation, all I have to do is add this:

<!-- the click event's propagation will be stopped -->
<a v-on:click.stop="doThis"></a>

Here's how I interpreted the example into my pug code:

b-dropdown(text="Actions")
  b-dropdown-item
    b-form(inline)
      .row
        .col
          b-input(@click.stop='' placeholder="#123")
          b-button(:href='printCheck' variant="primary") Print Check

It looks pretty simple, however it's not working as expected. If you need more supporting info, just ask. And feel free to tweak the title; I wasn't sure if my question is a vue, bootstrap-vue, or javascript question.

Thanks for your time in advance,
Kevin

Share Improve this question edited Jul 14, 2022 at 1:36 tony19 139k23 gold badges277 silver badges347 bronze badges asked Dec 5, 2018 at 19:48 RudyOnRailsRudyOnRails 1,9474 gold badges18 silver badges29 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Since you're clicking on a ponent you should bine .native with .stop modifiers like so :

 b-input(@click.native.stop='' placeholder="#123")

if you're using a simple HTML element like input you could use only .stop modifier:

 input(@click.stop='' placeholder="#123")

You can now use the new <b-dropdown-form> sub-ponent for placing input fields into dropdowns.

You should avoid placing input controls inside <b-dropdown-item> (which renders an <a> as it's root element), or <b-dropdown-item-button> (which renders a <button> as its root element). HTML5 doesn't like interactive elements inside <a> or <button> elements.

<b-dropdown-form> does not auto-close the dropdown when it is clicked.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论