vue3 鼠标悬停图片一秒后 在图片旁边生成一个大图
时间: 2023-08-04 19:16:46 浏览: 142
你可以使用 Vue 3 的 `v-if` 指令来动态控制大图的显示和隐藏。具体实现可以参考以下代码:
1. 在模板中添加鼠标悬停事件和大图的容器:
```html
<template>
<div>
<img src="small-image.jpg" @mouseover="showBigImage" @mouseleave="hideBigImage">
<div v-if="isShowBigImage" class="big-image-container">
<img src="big-image.jpg">
</div>
</div>
</template>
```
2. 在 `setup` 函数中定义响应式数据和方法:
```javascript
import { ref } from 'vue';
export default {
setup() {
const isShowBigImage = ref(false);
const showBigImage = () => {
setTimeout(() => {
isShowBigImage.value = true;
}, 1000);
};
const hideBigImage = () => {
isShowBigImage.value = false;
};
return {
isShowBigImage,
showBigImage,
hideBigImage,
};
},
};
```
3. 根据需要为大图容器添加样式:
```css
.big-image-container {
position: absolute;
top: 0;
left: 100%;
width: 400px;
height: 400px;
background-color: #fff;
border: 1px solid #ccc;
z-index: 999;
}
```
以上代码仅供参考,具体实现还需要根据实际情况进行调整。
阅读全文
相关推荐

















