参考: https://blog.csdn.net/dwb123456123456/article/details/82701740
https://blog.csdn.net/u014027876/article/details/81663080
https://www.jianshu.com/p/8601ccf91225

  1. 安装

    npm install  vue-awesome-swiper
    
    cnpm inatall vue-awesome-swiper
  2. main.js中引入
    import vueSwiper from 'vue-awesome-swiper'
  3. component - ShopSlide.vue 中引入
    import { swiper, swiperSlider } from 'vue-awesome-swiper'
    
    import 'swiper/dist/css/swiper.css'
    
    components: {
    
      swiper,
    
      swiperSlider
    
    }
  4. 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>
  5. 其他组件内引用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>
  6. 样式穿透
    <style scoped>
    
    .shopImg >>> .swiper-pagination-bullet-active{   
    
    background:#fff 
    
     }
    
    </style>

    <style lang="stylus" scoped>  //stylus是一种css预编译语言,支持省略花括号,支持省略分号,代码整洁,支持引入,并且支持语法内函数
    
    .shopImg >>> .swiper-pagination-bullet-active background:#fff  
    
    </style>

vue 可复用swiper以及scoped样式穿透(可以不受scoped的限制来修改样式)的更多相关文章

  1. vue样式穿透

    在一次这样的需求中,需要实现滑倒底部时自动请求数据,需要动态创建节点然后追加到某元素中,这期间遇到的问题就是在动态创建节点后,类名也已经加上了 ,但是样式就是没有生效,最后发现原因的产生竟然是< ...

  2. vue2.0 通过v-html指令渲染的富文本无法修改样式的解决方案

    在最近的vue项目中遇到的问题:v-html渲染的富文本,无法在样式表中修改样式: 比如下面的代码,div.descBox里面的p标签的color样式并不是"color: blue" ...

  3. Vue 中 css scoped 样式穿透 ( stylus[>>>] / sass / less[/deep/] )

    scoped看起来很好用,当时在Vue项目中,当我们引入第三方组件库时(如使用element-ui),需要在局部组件中修改第三方组件库样式,而又不想去除scoped属性造成组件之间的样式覆盖.这时我们 ...

  4. Vue中的scoped及穿透方法(修改第三方组件局部的样式)

    何为scoped? 在vue文件中的style标签上,有一个特殊的属性:scoped.当一个style标签拥有scoped属性时,它的CSS样式就只能作用于当前的组件,也就是说,该样式只能适用于当前组 ...

  5. Vue中的scoped及穿透方法

    何为scoped? 在vue文件中的style标签上,有一个特殊的属性:scoped.当一个style标签拥有scoped属性时,它的CSS样式就只能作用于当前的组件,也就是说,该样式只能适用于当前组 ...

  6. VUE中CSS样式穿透

    VUE中CSS样式穿透 1. 问题由来 在做两款H5的APP项目,前期采用微信官方推荐的weui组件库.后来因呈现的效果不理想,组件不丰富,最终项目完成后全部升级采用了有赞开发的vant组件库.同时将 ...

  7. 防止vue文件中的样式出现‘污染’情况(html5 scoped特性)

    近期在项目中出现了vue样式污染的情况: 一个页面刚进去时样式不正常,刷新之后,样式才才达到预期那样 在vue中,如果把样式写在vue文件的 style中,可能会出现样式污染的情况,这是要把写样式的标 ...

  8. vue加scoped后无法修改样式(无法修改element UI 样式)

    有的时候element提供的默认的样式不能满足项目的需要,就需要我们队标签的样式进行修改,但是发现修改的样式不起作用 第一种方法 原因:scoped 解决方法:去掉scoped 注意:此时该样式会污染 ...

  9. vue scss 样式穿透

    使用2个style的方式不够优雅,可以使用下面方式做样式穿透 .normal-field /deep/ .el-form-item { margin-bottom: 0px; } .normal-fi ...

随机推荐

  1. shell 命令 进程相关

     1. 进程标识号PID 唯一性 pid 为0    内核进程,linux内核创建 pid 为1    init进程,系统最早创建的进程,init是所有用户进程的祖先 2. 查看系统进程信息 (1)[ ...

  2. laravel 优化小记

    laravel 优化 7 Performance Optimization Tips for the Laravel Developer 运行 php artisan optimize php art ...

  3. 【JZOJ6277】矩阵游戏

    description analysis 设所有操作之后,\(f[i]\)表示\(i\)行乘的数,\(g[j]\)表示\(j\)列乘的数,那么 \[Answer=\sum^{n}_{i=1}\sum^ ...

  4. 长链接生成短链接Java源码(调用百度接口)

    public static DefaultHttpClient httpclient; static { httpclient = new DefaultHttpClient(); //httpcli ...

  5. 阿里云SaaS加速器“宜搭”发布宜搭Plus提升6倍研发效率

    9月26日,在杭州云栖大会上,阿里云SaaS加速器的“底座”——“宜搭”正式发布“宜搭Plus”低代码开发平台.开发复杂企业业务系统所需要的领域数据模型.逻辑&服务编排.专业UI页面设计等,都 ...

  6. jenkins实现不同角色查看不同视图

    1.安装插件Role-based Authorization Strategy 2.开启插件 系统管理>>>全局安全配置 3.创建角色和用户 4.登陆查看,只能看到travel开头的 ...

  7. PHP实现对短信验证码发送次数的限制

    http://www.jb51.net/article/94878.htm 对用户获取短信验证码的手机号.ip.和浏览器(使用唯一标识)进行限制.本文介绍的方法是对用户每天只能通过同一浏览器或同一ip ...

  8. idae for mac部分背景色修改收集

    文章目录 所有字体默认颜色 终端背景色 行数line number背景色 line number颜色 编码区背景色 光标所在行背景色 未被使用的变量.方法或者类 控制台相关 选中文字的背景色 选中和未 ...

  9. day4:Python列表(list)元组( tuple)字典(dict)

    列表----list 列表:中括号,每个元素用‘,’分割,列表里面也可以嵌套列表,列表里面可以包含数字,字符串,布尔值等,也就是元素的集合 例:test = [2,4,'sun','yao'] #索引 ...

  10. 猥琐发育,3月份Java干货已到达战场!

    时间真的过得很快,又是月底了,又到了我们总结这个月干货的时候了.3月份这个月我们都带来了哪些干货呢?我们一起回顾一下. 坑爹,手机端链接点不开,请切换到电脑端或者关注我们的微信公众号进行阅读. 扫描关 ...