javascript - 如何在Vue3.0中通过双击打开或关闭自动播放?
问题描述
我想在Vue3.0中通过双击打开或关闭自动播放。我尝试了很多次,但一直没有成功。
我想使用方法 'swiper.autoplay.stop()' 停止自动播放,但出现错误 "Uncaught TypeError: Cannot read property 'stop' of undefined'" 。
请告诉我该怎么做。谢谢。
这是我的 Vue 代码。
<template>
<swiper
:pagination="{ clickable: true }"
:grabCursor="grabCursor"
:effect="effect"
:loop="loop"
:centeredSlides=true
:autoplay="autoplay"
@slideChange="onSlideChange"
@doubleClick="ondblclick"
>
<swiper-slide v-for="item in arr" :key="item"><img :src="item" style="width: 100%;"></swiper-slide>
</swiper>
</template>
<script>
import 'swiper/components/effect-cube/effect-cube.scss'
import SwiperCore, { EffectCube, Pagination, Autoplay } from "swiper"
import { Swiper, SwiperSlide } from 'swiper/vue'
SwiperCore.use([EffectCube, Pagination, Autoplay])
export default {
components: {
Swiper,
SwiperSlide
},
data () {
return {
effect: 'cube',
grabCursor: true,
loop: true,
centeredSlides: true,
slidesPerView: 'auto',
autoplay: {
delay: 4000,
disableOnInteraction: false
},
arr: ['https://scpic.chinaz.net/files/pic/pic9/202101/apic30631.jpg']
}
},
methods: {
onSlideChange () {
},
ondblclick () {
}
}
}
</script>
<style scoped>
.swiper-container {
width: 330px;
height: 495px;
margin-top: 20px;
}
.swiper-slide {
background-position: center;
background-size: cover;
}
</style>
解决方案
推荐阅读
- javascript - 我可以将变量从我的 javascript 传递到 jsp 文件吗?
- swift - 如何在 SwiftUI 中将视图属性绑定到 ViewModel 属性
- xml - 如何在 Odoo 中使用 Wkhtmltopdf 打印尺寸准确的 div?
- php - 为数据库中的每个项目制作产品卡片
- extjs3 - FormPanel 折叠后 HTML 编辑器不可编辑
- reactjs - 使用带有 useState 的 double 类型并根据类型进行分配
- c# - C# 索引超出数组范围
- r - emacs 缺少 R 语法高亮显示
- html - 如何从自定义警报框中删除内边框并保留外边框
- c# - 我可以以某种方式在 FluentNhibernate 的同一张地图中分配身份 ID 吗?