vue使用vue-awesome-swiper插件,实现滚动条组件

效果图

src/components/scroll/index.vue

<template>
    <swiper class="swiper" :options="swiperOption">
    <swiper-slide>
        <!-- 所有内容放在插槽里 -->
        <slot></slot>
    </swiper-slide>
    <div class="swiper-scrollbar" slot="scrollbar"></div>
  </swiper>
</template>

<script>
  import { Swiper, SwiperSlide } from ‘vue-awesome-swiper‘;
  import ‘swiper/css/swiper.css‘;

  export default {
    name: ‘Scrollbar‘,
    title: ‘Scrollbar‘,
    components: {
      Swiper,
      SwiperSlide
    },
    data() {
      return {
        swiperOption: {
          scrollbar: {
            el: ‘.swiper-scrollbar‘,
            hide: true
          },
          direction:‘vertical‘,
          slidesPerView:‘auto‘,
          freeMode:true,
          setWrapperSize:true
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
    .swiper-container{
        width:100%;
        height:100%;
        overflow:hidden;
    }
    .swiper-wrapper{
        height:auto;
    }
    .swiper-slide{
        height:auto;
    }
</style>

src/pages/home/index.vue

<template>
    <div class="home">
        <scrollbar>
            <slider />
            <div class="content"></div>

        </scrollbar>
        <!-- 该页面自己的子路由 -->
        <router-view></router-view>
    </div>

</template>

<script>
import Slider from ‘components/slider‘;
import Scrollbar from ‘components/scroll‘;

export default {
    name:"Home",
    components:{
        Slider,
        Scrollbar
    }
}
</script>

<style scoped>
    .home{
        width:100%;
        height:100%;
    }
    .content{
        height:1000px;
    }
</style>

原文地址:https://www.cnblogs.com/chenyingying0/p/12641600.html

时间: 2024-08-04 01:08:00

vue使用vue-awesome-swiper插件,实现滚动条组件的相关文章

vue项目中使用swiper插件遇到的坑

<style scoped> .swiper-pagination-bullets  >>> .swiper-pagination-bullet-active {  background: orange; } /* >>> 在vue中有穿透的作用 */ </style> 原文地址:https://www.cnblogs.com/1609359841qq/p/12092723.html

vue中引入swiper插件

这里我们使用npm的方式安装swiper插件. 1.npm install vue-awesome-swiper --save 2.在main.js文件中引入文件 import Vue from 'vue' import VueAwesomeSwiper from 'vue-awesome-swiper' 3.然后注册全局的swiper Vue.use(VueAwesomeSwiper) 4.在模板中使用 //引入swiper.cssrequire('swiper/dist/css/swiper

解决几个vue中是swiper插件遇到的bug

1.在使用swiper插件的时候,如果内容都是静态资源的话不会出现错误,但是动态的话会出现划不动,或者白屏 分析:这种bug是怎样出现的,一般都是初始化的位置不对 方法: swiperInit() { var mySwiper = new Swiper('.swiper-container', { pagination : '.swiper', paginationType : 'bullets', autoplay : 200, }) } //这个是swiper的初始化方法,如果你是在crea

vue项目全局引入vue-awesome-swiper插件做出轮播效果

在安装了vue的前提下,打开命令行窗口,输入vue init webpack swiper-test,创建一个vue项目且名为swiper-test(创建速度可能会有点慢,耐心等),博文讲完后,源码托管在GitHub中,供下载并理解. vue项目自动生成完毕后,继续在命令行窗口输入cd swiper-test,将目录切换到swiper-test. 下面就开始启动vue项目了,输入启动命令行:npm run dev. 打开浏览器输入网址:localhost:8080 环境搭好了,进入主题,要想引入

[译]怎样在Vue.js中使用jquery插件

原文:http://gambardella.info/2016/09/05/guide-how-to-use-vue-js-with-jquery-plugins 使用Vue真的太棒了,但是也有可能使你头疼,当你试图使它与jquery插件混用的时候. 问题的原因是jquery与Vue是完全不同的东西,Vue是通过组件与数据绑定来进行渲染的,jquery则主要是用来做简单的单击处理和强大的操纵DOM的能力. 我试图寻找一些东西来帮助自己解决这个问题,但是我发现一些组件所做的工作不是很让我满意,所以

vue+elementUI封装的时间插件(有起始时间不能大于结束时间的验证)

vue+elementUI封装的时间插件(有起始时间不能大于结束时间的验证): html: <el-form-item label="活动时间" required> <el-col :xs="24" :sm="11" :md="7" :lg="5" class="startTime"> <el-form-item prop="start_time&

在Vue中使用了Swiper ,动态从后台获取数据的之后,swiper滑动失效??

在Vue中使用了Swiper ,动态从后台获取数据的之后,swiper滑动失效?? 是因为swiper提前初始化了,那时候数据还没有完全出来.这里有两种解决办法 1. 使用vue提供的$nextTick()方法 当Vue构造器里的data值被修改完成后会调用这个方法,也相当于一个钩子函数吧,和构造器里的updated生命周期很像. 在数据初始化完毕之后,再初始化swiper就不会出现问题了 this.$nextTick(function () { var swiper = new Swiper(

使用 Vue 开发 scrollbar 滚动条组件

Vue 应该说是很火的一款前端库了,和 React 一样的高热度,今天就来用它写一个轻量的滚动条组件: 知识储备:要开发滚动条组件,需要知道知识点是如何计算滚动条的大小和位置,还有一个问题是如何监听容器大小的改变,然后更新滚动条的位置: 先把样式贴出来: /*禁用选择文本*/ .disable-selection { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-use

Vue图片懒加载插件 - vue lazyload的简单使用

Vue module for lazyloading images in your applications. Some of goals of this project worth noting include: Be lightweight, powerful and easy to use Work on any image type Add loading class while image is loading Supports both of Vue 1.0 and Vue 2.0

vue-area-linkage Vue省市区三级列表联动插件使用

官方演示地址 // v5及之后的版本 数据依赖于area_data npm i --save vue-area-linkage area-data import Vue from 'vue'; import { pca, pcaa } from 'area-data'; // v5 or higher import 'vue-area-linkage/dist/index.css'; // v2 or higher import VueAreaLinkage from 'vue-area-lin