79474838

Date: 2025-02-28 08:02:04
Score: 0.5
Natty:
Report link

You can achieve this by using Vue's v-for directive along with @mouseover and @mouseleave events to track which item is being hovered.

<template>
  <div>
    <div
      v-for="(item, index) in items"
      :key="index"
      class="list-item"
      @mouseover="hoverIndex = index"
      @mouseleave="hoverIndex = null"
    >
      {{ item }}
      <button v-if="hoverIndex === index" @click="deleteItem(index)">Delete</button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const items = ref(["Item 1", "Item 2", "Item 3"]);
const hoverIndex = ref(null);

const deleteItem = (index) => {
  items.value.splice(index, 1);
};
</script>

<style scoped>
.list-item {
  padding: 10px;
  border: 1px solid #ccc;
  margin: 5px;
  position: relative;
  display: flex;
  justify-content: space-between;
}

button {
  background-color: red;
  color: white;
  border: none;
  cursor: pointer;
}
</style>
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @mouseover
  • User mentioned (0): @mouseleave
  • Low reputation (0.5):
Posted by: Vishal Solanki