当前位置: 首页 > 工具软件 > awesome-npm > 使用案例 >

vue-awesome-swiper的安装及使用

胡安怡
2023-12-01

1.安装

npm install vue-awesome-swiper --save

2.main.js 导入 和 注册

//引入swiper
import VueAwesomeSwiper from 'vue-awesome-swiper'
//引入swiper 样式
import 'swiper/css/swiper.css'
//注册插件
Vue.use(VueAwesomeSwiper)

3. 注册组件 (实测不用在 components 里注册组件,直接使用标签就可以)

<template>
  <div id="video-list">
    <swiper :options="swiperOption">
      <!-- 幻灯内容 -->
      <swiper-slide>slide1</swiper-slide>
      <swiper-slide>slide2</swiper-slide>
      <swiper-slide>slide3</swiper-slide>
      <swiper-slide>slide4</swiper-slide>
    </swiper>
  </div>
</template>

<script>
import { swiper, swiperSlide } from "vue-awesome-swiper" //导入组件

export default {
  data() {
    return {
      swiperOption: {
        direction: "vertical",
        grabCursor: true,
        setWrapperSize: true,
        autoHeight: true, //自动高度。设置为true时,wrapper和container会随着当前slide的高度而发生变化
        slidesPerView: 1,
        mousewheel: true,
        mousewheelControl: true,
        height: window.innerHeight, // 高度设置,占满设备高度
        resistanceRatio: 0,
        observeParents: true,
      },
    }
  },
}
</script>

<style scoped>
#video-list {
  background-color: black;
}
</style>

 类似资料: