首页 > 其他分享 >vue使用swiper调到指定页(非initialSlide)

vue使用swiper调到指定页(非initialSlide)

时间:2023-08-28 10:01:31浏览次数:49  
标签:index vue realIndex refs mySwiper true swiper initialSlide

使用swiper的Methods方法
watch: {
    showIndx(n){
      this.$nextTick(function () {
        this.$refs.mySwiper.swiper.slideTo(n, 1000, true)
      })
    },
  }
完整模板代码
<template>
    <swiper :options='swiperOption' ref="mySwiper" class='swiper-container swiper-no-swiping'>
        <swiper-slide>
              <div class='res1' @click='changeIndex(1)'></div>
                
        </swiper-slide>
        <swiper-slide>
            <one></one>    
        </swiper-slide>
        <swiper-slide>
            <two></two>
        </swiper-slide>
        <swiper-slide><three></three></swiper-slide>
        <!-- <swiper-slide><four></four></swiper-slide> -->
        <div class='swiper-pagination' slot='pagination'></div>
    </swiper>
</template>
<script>
export default {
  name: '',
  data () {
    return {
      swiperOption: {
        direction: 'vertical',
        slidesPerView: 1,
        spaceBetween: 30,
        mousewheel: true,
        lazyLoading : true,
        onSlideChangeEnd: swiper => {
          this.page = swiper.realIndex + 1
          this.index = swiper.realIndex
          alert(123)
        },
        fade:{crossFade:true},
        pagination: {
          el: '.swiper-pagination',
          clickable: true
        }
      },
      pathName:this.$route.name
    }
  },
    components: { 
    swiper,
    swiperSlide,
    one,
    two,
    three

    
  },
  computed: {
    swiper () {
      return this.$refs.mySwiper.swiper
    },
    change (swiper){
        console.log(swiper)
    }
  },
  // 测试

  methods:{
    //点击跳到对应的index页面
    changeIndex(index){
      console.log(this.$refs.mySwiper.swiper)
      this.$refs.mySwiper.swiper.slideTo(index, 1000, true);//切换到第一个slide,速度为1秒
      
    }
  }
}
  </script>

标签:index,vue,realIndex,refs,mySwiper,true,swiper,initialSlide
From: https://blog.51cto.com/u_14914383/7260326

相关文章

  • 鼠标任意拖动元素排列顺序(vue)
    参考地址:https://codesandbox.io/s/condescending-butterfly-enjqpr?file=/src/App.vue <template><div><transition-groupname="drag"class="list"tag="ul"><li@dragstart="dragStart(......
  • vue-颜色选择器(vColorPicker)
      //安装插件//官网:http://vue-color-picker.rxshc.com/npminstallvcolorpicker-S//main.js中全局引入importvcolorpickerfrom'vcolorpicker'Vue.use(vcolorpicker)//在页面中使用<colorPickerv-model="color"v-on:change="he......
  • vue3中使用provide/inject
    父组件<template><hello-world/><button@click="changeMessage">按钮</button></template><scriptsetuplang="ts">importHelloWorldfrom"./components/HelloWorld.vue";import{provide,ref......
  • Vue的使用(2)
    一个简单的Vue项目的创建创建一个UserList.vue组件在App.vue中使用该组件使用组件的第一步,导入组件使用组件的第二部,申明这个组件使用组件的第三步:引用组件结果:事件和插值语法<template><div><!--template只允许有一个唯一的孩子--><h1>这是一个一级标题</h1><di......
  • vue2
    介绍Vue.js是什么Vue(读音/vjuː/,类似于view)是一套用于构建用户界面的渐进式框架。Vue被设计为可以自底向上逐层应用。Vue.js使用了基于HTML的模板语法,允许开发者声明式地将DOM绑定至底层Vue实例的数据。所有Vue.js的模板都是合法的HTML,所以能被遵循规范的浏......
  • vue微信H5项目使用腾讯地图获取当前位置经纬度
    1.在index.html引入js文件<scriptsrc="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>2.在需要页面中你自己的key要去腾讯地图工具去申请https://lbs.qq.com/webApi/component/componentGuide/componentPickercreated(){this.getM......
  • vue项目打包之后, 生成一个可修改IP地址的文件
     在做项目的时候遇到了一个问题,就是把项目部署到不同的服务器上,但不能每次修改IP的时候就打包一次,这就增加了前端的工作量,经过百度,发现有一些方法是可以的,亲测可用。具体操作是,1,在static文件夹下面建立一个config.js文件, 1234567(function (){ ......
  • vue3探索——组件通信之v-model父子组件数据同步
    背景再很多场景中,我们可能想在子组件中修改父组件的数据,但事实上,vue不推荐我们这么做,因为数据的修改不容易溯源。Vue2写法在vue2中,我们使用.sync修饰符+自定义事件'update:xxx',来使父子组件数据同步。//父组件<template><div><h2>我是父组件,我有{{money}}¥......
  • vue中添加音频和视频
    视频播放功能1.安装vue-video-playernpminstallvue-video-player--save或yarnaddvue-video-player--save2.在main.js中全局引用importVueVideoPlayerfrom'vue-video-player'import'video.js/dist/video-js.css'import'vue-video-player/src/cu......
  • 小白整理了VUEX
    在小白开发的项目中前端使用的是Vue,虽然在日常工作中可以使用Vue进行开发工作。但是没有系统的学习过Vue,对Vue的一些特性和方法使用时常常需要查询资料解决问题,查询资料常常会占用大量时间,尤其对Vuex的使用。虽然可以通过很多Vue框架中带有的Vuex框架直接使用,但是用的越多,小白就会......