cr0w

-High end color matching

导航

统计

Nuxtjs 集成 swiper vue-awesome-swiper 插件

1、必须指定版本 不然各种坑 经测试通过如下

yarn add swiper@6.3.5

yarn add vue-awesome-swiper@3.1.3

2.项目中创建插件目录及文件

~/plugins/vue-awesome-swiper.js

import Vue from 'vue'
import VueAwesomeSwiper from 'vue-awesome-swiper'

Vue.use(VueAwesomeSwiper)

3.设置nuxtConfig

~/nuxt.config.js

export default {
    plugins: ['~/plugins/vue-awesome-swiper'],
}

4.在自己的组件中使用

~/pages/test.vue

复制代码
<template>
<div class="hello-world">
<transition name="fade">
<swiper id="swiperBox" ref="mySwiper" :options="swiperOption">
<!-- 第一页 -->
<swiper-slide class="swiper-slide1">
<div class="page">
<h3>第一页</h3>
</div>
</swiper-slide>
<!-- 第二页 -->
<swiper-slide class="swiper-slide2">
<div class="page">
<h3>第二页</h3>
</div>
</swiper-slide>
<!-- 第三页 -->
<swiper-slide class="swiper-slide3">
<div class="page">
<h3>第三页</h3>
</div>
</swiper-slide>
</swiper>
</transition>
</div>
</template>

<script>
export default {
name: 'TestPage',
components: {
},
layout: 'costomLayout',
data () {
return {
swiperOption: {
// swiper configs 所有的配置同swiper官方api配置
notNextTick: true,// notNextTick是一个组件自有属性,如果notNextTick设置为true,组件则不会通过NextTick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象,假如你需要刚加载遍使用获取swiper对象来做什么事,那么这个属性一定要是true
direction: 'vertical',// 水平方向移动
grabCursor: true,// 鼠标覆盖Swiper时指针会变成手掌形状,拖动时指针会变成抓手形状
setWrapperSize: true,// Swiper使用flexbox布局(display: flex),开启这个设定会在Wrapper上添加等于slides相加的宽或高,在对flexbox布局的支持不是很好的浏览器中可能需要用到。
autoHeight: true,// 自动高度。设置为true时,wrapper和container会随着当前slide的高度而发生变化
slidesPerView: 1,// 设置slider容器能够同时显示的slides数量(carousel模式)。可以设置为数字(可为小数,小数不可loop),或者 'auto'则自动根据slides的宽度来设定数量。loop模式下如果设置为'auto'还需要设置另外一个参数loopedSlides。
mousewheel: false,// 开启鼠标滚轮控制Swiper切换。可设置鼠标选项,默认值false
mousewheelControl: false,// 同上
height: window.innerHeight, // 高度设置,占满设备高度
resistanceRatio: 0,// 抵抗率。边缘抵抗力的大小比例。值越小抵抗越大越难将slide拖离边缘,0时完全无法拖离。本业务需要
observeParents: true,// 将observe应用于Swiper的父元素。当Swiper的父元素变化时,例如window.resize,Swiper更新

// 如果自行设计了插件,那么插件的一些配置相关参数,也应该出现在这个对象中,如下debugger
debugger: true,

// swiper的各种回调函数也可以出现在这个对象中,和swiper官方一样
}
}
},
computed: {
swiper() {
return this.$refs.mySwiper.swiper
}
},
mounted() {
this.swiper.slideTo(3, 1000, false)
}
}
</script>
<style scoped>
.fade-enter-active, .fade-leave-active {
transition: opacity .5s
}
.fade-enter, .fade-leave-to{
opacity: 0
}
.swiper-wrapper{
height: 100px;
}
.swiper-slide1{
background: skyblue;
}
.swiper-slide2{
background: yellowgreen;
}
.swiper-slide3{
background: blanchedalmond;
}
</style>
复制代码

 

posted on   cr0w  阅读(302)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示