在Vue JS中基于ID悬停显示Div

问题描述 投票:2回答:1

我有一个div,当我想悬停到它时,它会显示其他div。但是,我的第一个div是动态的,它有一个ID。那么我如何能够根据其ID转移到ID?

它应该是@mouseenter="hoverService{{services.id}} = true"但它会导致错误。所以我将下面的代码设为静态。

这是我的代码如下:

<template>
    <div
    class="col-md-3"
    v-for="(services, index) in servicesFiltered"
    :key="index"
    @mouseenter="hoverService = true"
    @mouseleave="hoverService = false"
    >
    <div class="service_background" v-if="hoverService">
        <div class="mb-1" v-for="(sub_services, index) in services.menu_items" :key="index">
        <router-link
            :to="{ path: `/${sub_services.data}`}"
        >
            <a
            href="#"
            class="btn btn-outline-primary w-100 services_button"
            >{{sub_services.text }}</a>
        </router-link>
        </div>
    </div>
    </div>
</template>


<script>
export default {
  data() {
    return {
      hoverService: false
    };
  }
};
</script>
vue.js vuejs2 vue-component vue-router
1个回答
1
投票

试试这个代码

https://codesandbox.io/s/y7p9qyyovz

您需要使用单个变量为多个项目维护无法操作的每个项目的悬停。

© www.soinside.com 2019 - 2024. All rights reserved.