P粉5643017822023-08-29 12:19:09
尝试将@mouseleave
事件移到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>