vue 可复用swiper以及scoped样式穿透(可以不受scoped的限制来修改样式)
2020-02-13 22:04
113 查看
参考: https://blog.csdn.net/dwb123456123456/article/details/82701740
https://blog.csdn.net/u014027876/article/details/81663080
https://www.jianshu.com/p/8601ccf91225
- 安装
npm install vue-awesome-swiper cnpm inatall vue-awesome-swiper
- main.js中引入
import vueSwiper from 'vue-awesome-swiper'
- component - ShopSlide.vue 中引入
import { swiper, swiperSlider } from 'vue-awesome-swiper' import 'swiper/dist/css/swiper.css' components: { swiper, swiperSlider }
- ShopSlide.vue代码
<template> <swiper :options="swiperOption" ref="mySwiper" v-bind:class="ifSlide?'':'swiper-no-swiping'"> <!-- slides --> <swiper-slide v-for="(picitem,index) in shopImgsList" :key="index"> <img :src="picitem.imgpath" alt="" style="display:inline-block;width:100%;vertical-align:middle;"> </swiper-slide> <div class="swiper-scrollbar" slot="scrollbar"></div> <div class="swiper-button-prev" slot="button-prev"></div> <div class="swiper-button-next" slot="button-next"></div> <div class="swiper-pagination pageIcon" slot="pagination"></div> </swiper> </template> <script> import { swiper, swiperSlider } from 'vue-awesome-swiper' import 'swiper/dist/css/swiper.css' export default { name: 'ShopSlide', data() { return { swiperOption: { notNextTick: true, loop: true, autoplay: 3000, speed: 800, direction: 'horizontal', grabCursor: true, setWrapperSize: true, autoHeight: true, autoplayDisableOnInteraction: false, // 如果需要分页符 pagination: '.swiper-pagination', // 如果需要前进后退按钮 nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', // 如果需要滚动条 scrollbar: '.swiper-scrollbar', paginationClickable: true, mousewheelControl: true, observeParents: true, debugger: true }, ImgsList: [], ifSlide: true } }, props: { shopImgsList: { type: Array, required: true } }, components: { swiper, swiperSlider }, watch: { shopImgsList: function(newVal, oldVal) { this.ImgsList = newVal; if(this.ImgsList.length == 1) { this.swiperOption.autoplay = false; this.ifSlide = false; } } } } </script> <style> .swiper-wrapper { font-size: 0; } .swiper-pagination.pageIcon { width: 3.75rem; height: .2rem; position: absolute; bottom: .1rem !important; text-align: center; line-height: .2rem; box-sizing: border-box; padding: 0 .3rem; font-size: 0; } .pageIcon span { background: rgba(0, 0, 0, .2); } .swiper-pagination-bullet-active { background-color: #ff7035 !important; opacity: 1; } .swiper-button-next { background-color: } .swiper-slide { width: 100%; height: 100% !important; line-height: 3.75rem !important; } .swiper-wrapper { height: 100% !important; line-height: 3.75rem !important; background-color: #fff; } .swiper-container-autoheight, .swiper-container-autoheight .swiper-slide { height: 100%; width: 100%; overflow: hidden; } </style>
- 其他组件内引用ShopSlide.vue
<template> <div class="shopImg"> <shop-slide :shopImgsList="shopImgsList"></shop-slide> </div> </template> <script> import ShopSlide from './ShopSlide.vue' export default{ data( ) { return{ shopImgList : [ { imgpath: '1.jpg '} , { imgpath: '2.jpg '}] } }, components: { ShopSlide } } <script>
- 样式穿透
<style scoped> .shopImg >>> .swiper-pagination-bullet-active{ background:#fff } </style>
或
<style lang="stylus" scoped> //stylus是一种css预编译语言,支持省略花括号,支持省略分号,代码整洁,支持引入,并且支持语法内函数 .shopImg >>> .swiper-pagination-bullet-active background:#fff </style>
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 使用scoped穿透方法实现修改vue中mint UI组件样式
- 理解Vue中的scoped实现原理及穿透方法 vue less不能修改第三方组件样式
- Vue中scoped穿透 修改子组件样式
- Vue中scoped穿透 修改第三方插件样式
- 如何在vue的scoped样式中修改element-ui的样式
- vue引入Swiper,背景颜色与轮播图片一致,更改前进后退按钮以及分页器样式,
- input文件上传,修改样式以及限制文件格式
- vue开发中,父组件添加scoped之后。解决在父组件中无法修改子组件样式问题。
- 前端vue中使用js-xlsx导出excel文件(可以修改样式)
- 在Vue.js中,在scoped模式下如何修改子组件内部标签的样式
- Element-ui el-input修改多行、单行文本框文字大小样式,以及用scoped覆盖原css样式
- 在Vue.js中,在scoped模式下如何修改子组件内部标签的样式
- vue修改UI框架样式 样式穿透
- 自定义View以及View的属性的使用(重点,xml中定义属性的值),包括Bitmap存为jpg样式(可以模仿修改照片不喜欢的地方)
- vue组件中的样式属性:scoped,解决在父组件中无法修改子组件样式问题
- sencha touch 扩展篇之使用sass自定义主题样式 (下)通过css修改官方组件样式以及自定义图标
- Vue 中, 修改Iview form表单的默认样式
- vsftp是不允许root用户登录的,可以通过修改限制来解决这个问题
- CSS3 Generator提供了13个CSS3较为常用的属性代码生成工具,而且可以通过这款工具除了在线生成效果代码之外,还可以实时看到你修改的效果,以及浏览器的兼容性。
- Vue中修改v-html引入内容的样式