Vue使用swiper遇到的一个小坑

1.已经执行过 npm install swiper --save 但是在npm run dev 的时候仍然报错
2.报错信息如下:提示我们swiper没有安装在这里插入图片描述
.
3. 然后进行疯狂的install 发现并没有用,最后查阅了网上的资料,发现是swiper版本问题
4.找到package.json 和 yarn.lock ,我发现自己的问题是package.json 里面swiper的版本是6.0.0
yarn.lock的版本是4.1.3,把package.json的版本改成yarn.lock里一样
5.install 一下,再启动,问题解决。

感谢原博主的分享:https://www.cnblogs.com/yizhilin/p/12993188.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,你可以按照以下步骤来使用VueSwiper一个可滚动的横向导航: 1. 安装SwiperVue-Swiper ``` npm install swiper vue-awesome-swiper --save ``` 2. 在Vue中导入Swiper ``` import Vue from 'vue' import VueAwesomeSwiper from 'vue-awesome-swiper' Vue.use(VueAwesomeSwiper) ``` 3. 使用Swiper创建轮播组件 ``` <template> <div class="swiper-container" ref="mySwiper"> <div class="swiper-wrapper"> <div class="swiper-slide" v-for="(item, index) in navList" :key="index" @click="handleClick(index)" :class="{active: currentIndex === index}">{{item}}</div> </div> </div> </template> <script> import Swiper from 'swiper' export default { data() { return { currentIndex: 0, navList: ['导航1', '导航2', '导航3', '导航4', '导航5', '导航6', '导航7', '导航8', '导航9', '导航10', '导航11', '导航12'] } }, mounted() { const swiper = new Swiper(this.$refs.mySwiper, { slidesPerView: 'auto', spaceBetween: 30, freeMode: true }) }, methods: { handleClick(index) { this.currentIndex = index } } } </script> <style> .swiper-container { padding: 20px 0; } .swiper-slide { display: flex; justify-content: center; align-items: center; border-radius: 20px; padding: 10px 20px; cursor: pointer; transition: all .3s; color: #333; &.active { background-color: #f60; color: #fff; } } </style> ``` 这样就可以创建一个可滚动的横向导航了,使用Swiper的`slidesPerView`属性设置每个导航按钮占据的宽度,使用`spaceBetween`属性设置导航按钮之间的距离,使用`freeMode`属性开启自由模式,让导航按钮可以自由滚动。在点击导航按钮的时候通过`handleClick`方法来改变当前选中的导航,从而改变样式。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值