ElementUI Carousel 取消hover暂停轮播的默认行为

Carousel 在根节点上绑定了 mouseenter 和 mouseleave:

复制代码
// carousel 源码中的模板`
`on:` `{`
  `mouseenter:` `function($event)` `{`
      `_vm.handleMouseEnter($event)`              
  `},`
  `mouseleave:` `function($event)` `{`
      `_vm.handleMouseLeave($event)` 
  `}`
`}`
`

默认handleMouseEnter和handleMouseLeave事件为:鼠标移入的时候会暂停轮播,鼠标移出会恢复轮播。

复制代码
handleMouseEnter()` `{`
  `this.hover =` `true;`   `// 用于控制箭头显示`
  `this.pauseTimer();`   `// 暂停轮播`
`},`
`handleMouseLeave()` `{`
  `this.hover =` `false;`
  `this.startTimer();`   `// 恢复轮播`
`}`
`

取消轮播方式,重写这两个方法:

复制代码
` `<el-carousel ref="bannerCarousel"` `:height="bannerHeight"` `:interval="3000" arrow="hover" indicator-position="none" @change="onBannerChange">`
        `<el-carousel-item v-for="(slide, index) in slides"` `:key="slide.key">`
          `<div class="banner-slide">`
            `<img class="banner-img"` `:src="shouldLoadBanner(index) ? getBannerImgUrl(slide.img) : ''"` `:alt="slide.title"/>`
          `</div>`
        `</el-carousel-item>`
      `</el-carousel>`
`
复制代码
const carousel =` `this.$refs.bannerCarousel`
`carousel.handleMouseEnter` `=` `function` `()` `{` 
    `this.hover =` `true` 
`}`
`carousel.handleMouseLeave` `=` `function` `()` `{` 
    `this.hover =` `false` 
`}`
`
相关推荐
candyTong7 小时前
一觉醒来,大模型就帮我排查完页面性能问题
前端·javascript·架构
魔术师Grace7 小时前
我给 AI 做了场入职培训
前端·程序员
玩嵌入式的菜鸡8 小时前
网页访问单片机设备---基于mqtt
前端·javascript·css
前端一小卒8 小时前
我用 Claude Code 的 Superpowers 技能链写了个服务,部署前差点把服务器搞炸
前端·javascript·后端
滑雪的企鹅.10 小时前
HTML头部元信息避坑指南大纲
前端·html
一拳不是超人10 小时前
老婆天天吵吵要买塔罗牌,我直接用 AI 2 小时写了个在线塔罗牌
前端·ai编程
阿丰资源11 小时前
SpringBoot+Vue实战:打造企业级在线文档管理系统
vue.js·spring boot·后端
excel11 小时前
如何解决 Nuxt DevTools 中关于 unstorage 包的报错
前端
Rust研习社11 小时前
使用 Axum 构建高性能异步 Web 服务
开发语言·前端·网络·后端·http·rust
C澒12 小时前
AI 生码 - API2Code:接口智能匹配与 API 自动化生码全链路设计
前端·低代码·ai编程