How to deal with the problem of mouse entering, mouse leaving and content drop-down menu not disappearing in Vue.js 2
P粉226667290
P粉226667290 2023-08-28 12:58:10
0
1
477
<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粉226667290
P粉226667290

reply all(1)
P粉564301782

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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!