Home  >  Q&A  >  body text

How to deal with the problem of mouse entering, mouse leaving and content drop-down menu not disappearing in Vue.js 2

<p>Hi everyone, I would like to know how to use <code>@mouseenter</code> and <code>@mouseleave</code> to control the dropdown content instead of making it disappear</p> <pre class="brush:php;toolbar:false;"><div class="wrapper"> <div class="link" @mouseenter="show = true" @mouseleave="show = false">project</div> <div class="content" v-if="show">This is content</div> </div></pre> <p>I tried something like this but I don't know how to handle it when I want to hover over or interact with the content, hope you guys can help me. Thank you in advance. </p>
P粉226667290P粉226667290389 days ago467

reply all(1)I'll reply

  • P粉564301782

    P粉5643017822023-08-29 12:19:09

    Try to move the @mouseleave event into content:

    new Vue({
      el: "#app",
      data: {
        show: false,
        links: [1,2,3,4,5],
        linkId: null
      },
    })
    .wrapper{
      display: grid;
      justify-content: start;
      width: 200px;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
    <div id="app">
    <div class="wrapper" @mouseleave="linkId = null">
      <ul>
        <li v-for="link in links" :key="link">
          <div class="link" @mouseenter.prevent="linkId = link" >Item{{ link }}</div>
          <div class="content" v-if="link === linkId" @mouseleave.prevent="linkId = null">这是一个内容</div>
        </li>
      </ul>
    </div>
    </div>

    reply
    0
  • Cancelreply