vue中修改swiper样式

当你在vue中使用swiper时,你会发现,你直接修改swiper里面的样式,是修改不成功的。

原因:

vue文件中的template,和style 都会经过vue-loader的编译。在style标签上使用了 scoped 属性的话,template中手写的元素和style之间会通过vue-loader生成的一个自定义属性,形成呼应关系,style只对对应的template起作用。编译过程中由swiper 生成的分页器标签不会经过vue-loader的编译,所以选不到。

解决方法:

方法一:样式穿透

<style lang="scss" scoped>
    ::v-deep .swiper-pagination-bullet {
      width: 6px;
      height: 6px;
      background-color: #FFFFFF;
      opacity: 1;

    }
    ::v-deep .swiper-pagination-bullet-active {
      width: 14px;
      height: 6px;
      border-radius: 3px;
      opacity: 1;
      background-color: #FFFFFF;
    }
</style>

 方法二:在<style lang="scss" scoped></style>下面再写一个<style></style>不加scoped

<style>
.swiper-pagination-bullet {
  width: 6px;
  height: 6px;
  background-color: #FFFFFF;
  opacity: 1;

}
.swiper-pagination-bullet-active {
  width: 14px;
  height: 6px;
  border-radius: 3px;
  opacity: 1;
  background-color: #FFFFFF;
}
</style>

 修改样式之前:

修改样式之后:

 

 我就是把分页的样式修改了一下。

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Swiper Navigation 可以通过修改 CSS 样式来自定义样式。具体步骤如下: 1. 在 HTML 添加 Navigation 的 HTML 结构,例如: ```html <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide">Slide 1</div> <div class="swiper-slide">Slide 2</div> <div class="swiper-slide">Slide 3</div> </div> <div class="swiper-pagination"></div> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> </div> ``` 2. 在 CSS 添加 Navigation 的样式,例如: ```css .swiper-button-prev, .swiper-button-next { position: absolute; top: 50%; width: 27px; height: 44px; margin-top: -22px; z-index: 10; cursor: pointer; background-image: url(../images/arrow.png); background-repeat: no-repeat; background-position: center; } .swiper-button-prev { left: 10px; transform: rotate(180deg); } .swiper-button-next { right: 10px; } ``` 3. 在 Vue 使用 Swiper Navigation,例如: ```vue <template> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide">Slide 1</div> <div class="swiper-slide">Slide 2</div> <div class="swiper-slide">Slide 3</div> </div> <div class="swiper-pagination"></div> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> </div> </template> <script> import Swiper from 'swiper'; import 'swiper/swiper-bundle.css'; export default { mounted() { const swiper = new Swiper('.swiper-container', { navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, }); }, }; </script> <style> .swiper-button-prev, .swiper-button-next { position: absolute; top: 50%; width: 27px; height: 44px; margin-top: -22px; z-index: 10; cursor: pointer; background-image: url(../images/arrow.png); background-repeat: no-repeat; background-position: center; } .swiper-button-prev { left: 10px; transform: rotate(180deg); } .swiper-button-next { right: 10px; } </style> ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

阿wei程序媛

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

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

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

打赏作者

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

抵扣说明:

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

余额充值