基于之前写的vue2.0 + vue-cli + webpack 搭建项目( vue-awesome-swiper版本:3.1.3 ,swiper4,如果成功后没报错,但不显示分页样式,可能版本对不上)

1.进入项目目录,安装swiper

npm install vue-awesome-swiper --save

2.引入资源(main.js文件)

import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.use(VueAwesomeSwiper)

3.编辑组件(HelloWorld.vue文件或其他 .vue文件)

<template>
<swiper :options="swiperOption" ref="mySwiper">
<!-- slides -->
<swiper-slide>I'm Slide 1</swiper-slide>
<swiper-slide>I'm Slide 2</swiper-slide>
<swiper-slide>I'm Slide 3</swiper-slide>
<swiper-slide>I'm Slide 4</swiper-slide>
<swiper-slide>I'm Slide 5</swiper-slide>
<swiper-slide>I'm Slide 6</swiper-slide>
<swiper-slide>I'm Slide 7</swiper-slide> <div class="swiper-pagination" slot="pagination"></div>
<div class="swiper-button-prev" slot="button-prev"></div>
<div class="swiper-button-next" slot="button-next"></div> </swiper>
</template>
<script>
import { swiper, swiperSlide } from 'vue-awesome-swiper'
require('swiper/dist/css/swiper.css')
export default {
name: 'carrousel',
components: {
swiper,
swiperSlide
},
data() {
return {
swiperOption: { notNextTick: true, //循环
loop:true,
//设定初始化时slide的索引
initialSlide:0, //自动播放
autoplay: {
delay: 3000,
//触摸后还可以自动播放
disableOnInteraction: false,
}, //滑动速度
speed:400, //水平切换
direction : 'horizontal', //左右点击
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}, //滑动之后回调函数
on: {
slideChange: function () {
//第几页
console.log(this.activeIndex);
},
},
//分页器设置
pagination: {
el: '.swiper-pagination',
clickable :true,
//自定义类型(至此以下不写是默认圆点样式)
type: 'custom',
//自定义分页器样式
renderCustom: function (swiper, current, total) {
const activeColor = '#555555'
const normalColor = '#aeaeae'
let color = ''
let paginationStyle = ''
let html = ''
for (let i = 1; i <= total; i++) {
if (i === current) {
color = activeColor
} else {
color = normalColor
}
paginationStyle = `background:${color};opacity:1;margin-right:20px;width:20px;height:20px;transform:skew(15deg);border-radius:0;`
html += `<span class="swiper-pagination-bullet" style=${paginationStyle}></span>`
}
return html
}
}, }
}
}, // 如果你需要得到当前的swiper对象来做一些事情,你可以像下面这样定义一个方法属性来获取当前的swiper对象,同时notNextTick必须为true
computed: {
swiper() {
return this.$refs.mySwiper.swiper
}
},
mounted() { // 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
// console.log('this is current swiper instance object', this.swiper)
// this.swiper.slideTo(3, 1000, false)
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.swiper-container{
height:200px;
overflow: hidden
}
.swiper-wrapper{
height:200px;
}
.swiper-slide{
height:200px;
float: left;
background:red;
} </style>

使用vue-awesome-swiper滑块插件的更多相关文章

  1. 用原生js来写一个swiper滑块插件

        是不是有点印象了,没错,他的最基本的用法就是左右滑动,插件使用者只需要写几行简单的html和js即可实现一个简单滑动效果,不过你完全可以组合各种元素来适应不同的场景. 当然插件我已经写好了,咱 ...

  2. Swiper – 经典的移动触摸滑块插件【免费】

    Swiper 是移动 Web 开发中最常用的滑块插件,是一款免费的,最现代化的移动触摸滑块,支持硬件加速的转换和惊人的原生表现.它的目的是在移动网站,移动 Web 应用程序和 Hygrid 混合应用程 ...

  3. vue自制switch滑块

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. vue引入swiper vue使用swiper vue脚手架使用swiper /引入js文件/引入css文件

    vue引入swiper  vue使用swiper  vue脚手架使用swiper /引入js文件/引入css文件 ------------------------------------------- ...

  5. vue添加swiper的正确方式亲测---切图网

    在vue项目中,我们在做图片轮播的方式和传统切图不同,传统切图中我们一般采用非常强大的swiper来完成,而在vue中一般依赖vue-awesome-swiper组件来完成(vue-awesome-s ...

  6. VUE常用UI组件插件及框架

    UI组件及框架 element - 饿了么出品的Vue2的web UI工具套件 mint-ui - Vue 2的移动UI元素 iview - 基于 Vuejs 的开源 UI 组件库 Keen-UI - ...

  7. 分享22款响应式的 jQuery 图片滑块插件

    响应式(Responsive)设计的目标是要让产品界面能够响应用户的行为,根据不同终端设备自动调整尺寸,带给用户良好的使用体验.这篇文章收集了22款优秀的响应式 jQuery 幻灯片插件,它们能够帮助 ...

  8. Glide.js:响应式 & 触摸友好的 jQuery 滑块插件

    Glide.js 是一款响应式和对触摸友好的 jQuery 滑块.基于 CSS3 转换实现,并在低版本浏览器降级处理.Glide.js 简单,重量轻,快速,适用于智能手机,平板电脑和台式机.它支持 s ...

  9. 11个新鲜出炉的jQuery图像滑块插件

    如今图像滑块已成为一种流行的Web设计元素,通过滑块,你可以在有限的页面空间中展示更多的内容,带给用户更佳的浏览体验.本文将为你带来一些非常实用的jQuery图像滑块插件. 1.  Basic Sli ...

  10. 15 个响应式的 jQuery 图像滑块插件

    设计师和开发人员总是试图使用新技术让网站更智能,而我们发现在许多网站上 jQuery 的图像滑块插件是非常受欢迎的.本文继续介绍 15 个 jQuery 图像滑块插件以供您选择. ELASTISLID ...

随机推荐

  1. Windows下安装配置PLSQL

    说明:1.PLSQL Developer是远程连接Oracle数据库的一个可视化工具,并且其不是一个独立的软件,是需要依赖Oracle客户端运行的.2.本安装教程是基于本机没有安装Oracle数据库的 ...

  2. Python匹马行天下之面向对象

    概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发“更快更好更强...” 面向过程编程最易被初学 ...

  3. Python匹马行天下之_循环

    一.while循环 如果条件成立(true),重复执行相同操作,条件不符合,跳出循环 while   循环条件: 循环操作 (1)while循环示例 例:输入王晓明5门课程的考试成绩,计算平均成绩 1 ...

  4. NEO4J亿级数据全文索引构建优化

    NEO4J亿级数据全文索引构建优化 一.数据量规模(亿级) 二.构建索引的方式 三.构建索引发生的异常 四.全文索引代码优化 1.Java.lang.OutOfMemoryError 2.访问数据库时 ...

  5. 【ArcObject】 AxTocControl:实现图层可移动

    设置axTocControl属性:EnableLayerDragDrop 为true即可

  6. jupyter中使用graphviz

    参考: https://www.cnblogs.com/zhanjiahui/p/11335038.html https://blog.csdn.net/linxid/article/details/ ...

  7. robotframework冷门关键字

    1.Reload Page 模拟页面重载 2.Register Keyword To Run On Failure 参数: Keyword 描述: 当Selenium2Library类库关键字执行失败 ...

  8. delphi 还原窗口

    1.格局还原procedure TFrmStyleProp.btnNewClick(Sender: TObject); //声明var iniFile : TIniFile; idx : intege ...

  9. 线程池ThreadPoolExecutor工作原理

    前言 工作原理 如果使用过线程池,细心的同学肯定会注意到,new一个线程池,但是如果不往里面提交任何任务的话,main方法执行完之后程序会退出,但是如果向线程池中提交了任务的话,main方法执行完毕之 ...

  10. Let's Encrypt 安装配置教程,免费的 SSL 证书

    官网:https://letsencrypt.org/ 安装Let's Encrypt 安装非常简单直接克隆就可以了 git clone https://github.com/letsencrypt/ ...