vue 可复用swiper以及scoped样式穿透(可以不受scoped的限制来修改样式)
参考: 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>
vue 可复用swiper以及scoped样式穿透(可以不受scoped的限制来修改样式)的更多相关文章
- vue样式穿透
在一次这样的需求中,需要实现滑倒底部时自动请求数据,需要动态创建节点然后追加到某元素中,这期间遇到的问题就是在动态创建节点后,类名也已经加上了 ,但是样式就是没有生效,最后发现原因的产生竟然是< ...
- vue2.0 通过v-html指令渲染的富文本无法修改样式的解决方案
在最近的vue项目中遇到的问题:v-html渲染的富文本,无法在样式表中修改样式: 比如下面的代码,div.descBox里面的p标签的color样式并不是"color: blue" ...
- Vue 中 css scoped 样式穿透 ( stylus[>>>] / sass / less[/deep/] )
scoped看起来很好用,当时在Vue项目中,当我们引入第三方组件库时(如使用element-ui),需要在局部组件中修改第三方组件库样式,而又不想去除scoped属性造成组件之间的样式覆盖.这时我们 ...
- Vue中的scoped及穿透方法(修改第三方组件局部的样式)
何为scoped? 在vue文件中的style标签上,有一个特殊的属性:scoped.当一个style标签拥有scoped属性时,它的CSS样式就只能作用于当前的组件,也就是说,该样式只能适用于当前组 ...
- Vue中的scoped及穿透方法
何为scoped? 在vue文件中的style标签上,有一个特殊的属性:scoped.当一个style标签拥有scoped属性时,它的CSS样式就只能作用于当前的组件,也就是说,该样式只能适用于当前组 ...
- VUE中CSS样式穿透
VUE中CSS样式穿透 1. 问题由来 在做两款H5的APP项目,前期采用微信官方推荐的weui组件库.后来因呈现的效果不理想,组件不丰富,最终项目完成后全部升级采用了有赞开发的vant组件库.同时将 ...
- 防止vue文件中的样式出现‘污染’情况(html5 scoped特性)
近期在项目中出现了vue样式污染的情况: 一个页面刚进去时样式不正常,刷新之后,样式才才达到预期那样 在vue中,如果把样式写在vue文件的 style中,可能会出现样式污染的情况,这是要把写样式的标 ...
- vue加scoped后无法修改样式(无法修改element UI 样式)
有的时候element提供的默认的样式不能满足项目的需要,就需要我们队标签的样式进行修改,但是发现修改的样式不起作用 第一种方法 原因:scoped 解决方法:去掉scoped 注意:此时该样式会污染 ...
- vue scss 样式穿透
使用2个style的方式不够优雅,可以使用下面方式做样式穿透 .normal-field /deep/ .el-form-item { margin-bottom: 0px; } .normal-fi ...
随机推荐
- cmd命令符
运行操作 CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本.文件系统版本) CMD命令锦集 1. gpedit.msc-----组策略 2. ...
- 【JZOJ4474】【luoguP4071】排列计数
description 求有多少种长度为 n 的序列 A,满足以下条件: (1)1 ~ n 这 n 个数在序列中各出现了一次 (2)若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列恰好有 ...
- 用shell脚本执行php删除缓存文件
<?php #定义删除路径//服务器缓存目录的路径 $path = '/www/wwwroot/****/data/runtime'; #调用删除方法 deleteDir($path); fun ...
- day11 grep正则匹配
ps aus | trep nginx # 查看所有正在运行的nginx任务 别名路径: alias test_cmd='ls -l' PATH路径: 临时修改: PATH=$PATH:/usr/lo ...
- Form-Item Slot 自定义label内容
<el-form-item> <span slot="label">体 重:</span> <el-input v-model=&qu ...
- 尚学python课程---14、python中级语法
尚学python课程---14.python中级语法 一.总结 一句话总结: var[1:5] 访问模式:比如字符串,比如列表元祖,字典等 del 删除模式:比如列表.元祖.字典 1.Python的N ...
- C语言进阶学习第一章
1.在C语言里面使用scanf给某个变量赋值时候,如果成功返回1,失败返回0:测试代码如下: /***假如在键盘输入的不是整形数据,则输出0,否则输出1***/ void main() { int a ...
- HTTP协议基础篇(帮助理解)
用uml 来描述一个功能是怎样按照时间的顺序完成的 实际的需求(配置网站/配置虚拟主机) 步骤 (1) 打开 apache/conf/httpd.conf 文件 (2)找到hosts文件 c:/win ...
- vue通过修改element-ui相关类的样式修改element-ui组件的样式
可以在App.vue中的style中修改element-ui的样式. .el-menu{ width:160px !important; } 注意:一定要在属性值后面加上 !important 使自己 ...
- <python基础>封装,继承,多态,重写,重载
什么是封装? 所谓的面向对象就是将我们的程序模块化,对象化,把具体事物的特性属性和通过这些属性来实现一些动作的具体方法放到一个类里面,这就是封装.封装是我们所说的面相对象编程的特征之一.除此之外还有继 ...