vue.js做轮播图

vue.js做轮播图只需三步第一步,<template>写入

<template>
    <view id = "app">
            <view class="imgItems" @mouseover = "onmouseover" @mouseup="onmouseup" >
                <image src="../../static/img/1.png" alt="" class="img indexZ"></image>
                <image src="../../static/img/2.png" alt="" class="img"></image>
                <image src="../../static/img/3.png" alt="" class="img"></image>
            </view>
        </view>
</template>

第二步,<script>写入

export default {
        // el:"app",
        props:{
            title:{
                default:"",
                type:St

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Vue.js可以通过使用第三方插件或者自己编写组件来实现轮播图。以下是一个常用的方式: 1. 使用vue-awesome-swiper插件 vue-awesome-swiper是一个基于Swiper的轮播图插件,可以快速实现轮播图功能。 安装: ``` npm install vue-awesome-swiper --save ``` 使用: ```html <template> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide" v-for="item in list" :key="item.id"> <img :src="item.imgUrl" alt=""> </div> </div> <div class="swiper-pagination"></div> </div> </template> <script> import 'swiper/dist/css/swiper.css' import { swiper, swiperSlide } from 'vue-awesome-swiper' export default { components: { swiper, swiperSlide }, data() { return { list: [ { id: 1, imgUrl: 'http://xxx/1.jpg' }, { id: 2, imgUrl: 'http://xxx/2.jpg' }, { id: 3, imgUrl: 'http://xxx/3.jpg' } ], swiperOption: { pagination: { el: '.swiper-pagination' }, loop: true } } }, mounted() { console.log('mounted') } } </script> ``` 2. 自己编写组件 如果需要自定义轮播图的样式和交互,可以自己编写组件实现。 ```html <template> <div class="carousel"> <div class="carousel-item" v-for="(item, index) in list" :key="index"> <img :src="item.imgUrl" alt=""> </div> <div class="carousel-nav"> <span class="carousel-nav-item" v-for="(item, index) in list" :key="index" :class="{active: currentIndex === index}" @click="handleClick(index)"> </span> </div> </div> </template> <script> export default { data() { return { list: [ { id: 1, imgUrl: 'http://xxx/1.jpg' }, { id: 2, imgUrl: 'http://xxx/2.jpg' }, { id: 3, imgUrl: 'http://xxx/3.jpg' } ], currentIndex: 0 } }, mounted() { this.autoPlay() }, methods: { autoPlay() { setInterval(() => { this.currentIndex = (this.currentIndex + 1) % this.list.length }, 2000) }, handleClick(index) { this.currentIndex = index } } } </script> <style scoped> .carousel { position: relative; width: 500px; height: 300px; overflow: hidden; } .carousel-item { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; transition: opacity 0.3s; } .carousel-item.active { opacity: 1; } .carousel-nav { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; } .carousel-nav-item { width: 10px; height: 10px; margin-right: 10px; border-radius: 50%; background-color: #fff; cursor: pointer; } .carousel-nav-item.active { background-color: #f00; } </style> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

笔者籁龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值