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` 
`}`
`
相关推荐
之歆1 分钟前
DAY_12JavaScript DOM 完全指南(三):高级工程篇
开发语言·前端·javascript·ecmascript
来恩10036 分钟前
EL表达式应用
前端·javascript·vue.js
希冀1236 分钟前
【CSS学习第十篇】
前端·css
小飞侠是个胖子15 分钟前
在 WebGL 中构建高性能 3D 沉浸式系统的三套高阶方案
前端·3d
wh_xia_jun17 分钟前
Vue3 + Vitest 浏览器测试 从零开发指南
前端·javascript·vue.js
FlyWIHTSKY19 分钟前
区块链前端技术栈介绍
前端·区块链
唐青枫20 分钟前
别再让 key 写成字符串:TypeScript keyof 从入门到实战
前端·javascript·typescript
一点一木8 小时前
深度体验TRAE SOLO移动端7天:作为独立开发者,我把工作流揣进了兜里
前端·人工智能·trae
天外飞雨道沧桑8 小时前
TypeScript 中 omit 和 record 用法
前端·javascript·typescript
Lee川9 小时前
mini-cursor 揭秘:从 Tool 定义到 Agent 循环的完整实现
前端·人工智能·后端