【问题标题】:Show Div When Hover Based on ID in Vue JS在Vue JS中根据ID悬停时显示Div
【发布时间】:2019-07-10 05:06:09
【问题描述】:

我有一个 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】:

    试试这个代码

    https://codesandbox.io/s/y7p9qyyovz

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-22
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-23
      相关资源
      最近更新 更多