使用vue-awesome-swiper滑块插件
基于之前写的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滑块插件的更多相关文章
- 用原生js来写一个swiper滑块插件
是不是有点印象了,没错,他的最基本的用法就是左右滑动,插件使用者只需要写几行简单的html和js即可实现一个简单滑动效果,不过你完全可以组合各种元素来适应不同的场景. 当然插件我已经写好了,咱 ...
- Swiper – 经典的移动触摸滑块插件【免费】
Swiper 是移动 Web 开发中最常用的滑块插件,是一款免费的,最现代化的移动触摸滑块,支持硬件加速的转换和惊人的原生表现.它的目的是在移动网站,移动 Web 应用程序和 Hygrid 混合应用程 ...
- vue自制switch滑块
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue引入swiper vue使用swiper vue脚手架使用swiper /引入js文件/引入css文件
vue引入swiper vue使用swiper vue脚手架使用swiper /引入js文件/引入css文件 ------------------------------------------- ...
- vue添加swiper的正确方式亲测---切图网
在vue项目中,我们在做图片轮播的方式和传统切图不同,传统切图中我们一般采用非常强大的swiper来完成,而在vue中一般依赖vue-awesome-swiper组件来完成(vue-awesome-s ...
- VUE常用UI组件插件及框架
UI组件及框架 element - 饿了么出品的Vue2的web UI工具套件 mint-ui - Vue 2的移动UI元素 iview - 基于 Vuejs 的开源 UI 组件库 Keen-UI - ...
- 分享22款响应式的 jQuery 图片滑块插件
响应式(Responsive)设计的目标是要让产品界面能够响应用户的行为,根据不同终端设备自动调整尺寸,带给用户良好的使用体验.这篇文章收集了22款优秀的响应式 jQuery 幻灯片插件,它们能够帮助 ...
- Glide.js:响应式 & 触摸友好的 jQuery 滑块插件
Glide.js 是一款响应式和对触摸友好的 jQuery 滑块.基于 CSS3 转换实现,并在低版本浏览器降级处理.Glide.js 简单,重量轻,快速,适用于智能手机,平板电脑和台式机.它支持 s ...
- 11个新鲜出炉的jQuery图像滑块插件
如今图像滑块已成为一种流行的Web设计元素,通过滑块,你可以在有限的页面空间中展示更多的内容,带给用户更佳的浏览体验.本文将为你带来一些非常实用的jQuery图像滑块插件. 1. Basic Sli ...
- 15 个响应式的 jQuery 图像滑块插件
设计师和开发人员总是试图使用新技术让网站更智能,而我们发现在许多网站上 jQuery 的图像滑块插件是非常受欢迎的.本文继续介绍 15 个 jQuery 图像滑块插件以供您选择. ELASTISLID ...
随机推荐
- 20130318 word2013 mathtype
1.word2013 下如何安装mathtype 1.word2013已经装好 2.下载mathtype6.9 3. 公式编辑器Mathtype安装后无法加载到word的解决办法http://w5 ...
- 推荐5本纯Java技术书,你看过几本?
51小长假了,大家应该对它又爱又痛,爱的是终于可以到处浪了,痛的是没钱只能穷游,而且还到处都是人,结果变成了堵高速.去看人头.去蒸饺子,真是受罪啊.. 所以,对于小长假的痛,我相信还是有一部分人会选择 ...
- 干货:Java技术栈18年02月精彩好文汇总
一晃眼,一个月过去了,新年也过完了. 一晃眼,又老了一岁了,感觉新的一年压力更大了. 我们也该为这一个月的技术做做汇总了,错过的同学正好可以统一回顾看看,已经看过的同学也可以再温习一下.. Java技 ...
- USACO 2011 November Cow Lineup /// map set 尺取法 oj25279
题目大意: 输入n 接下来n行描述n头牛的编号num和品种id 得到包含所有id的最短段 输出最短段的编号差 Sample Input 625 726 115 122 320 130 1 Sample ...
- iOS音频开发系列-概述篇
概述 iOS中对于音频的处理,苹果提供了两个库. AVFoundation AudioToolbox 在iOS系统中apple对上述的流程进行了封装并提供了不同层次的接口
- nginx代理配置备份
补充: 代理对文件大小的限制, server {client_max_body_size 100M;listen 9096;server_name gate.chaohuoyy.com; locati ...
- vue组件的props
刚开始学习vue组件的时候经常被 props这个传值搞晕,做个笔记 Vue.component('item', { template: '#item-template', props: { model ...
- vue(1) 第一个例子
代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- js数学公式-曲线运动
---勾股定理 a*a + b*b =c*c ---三角函数 正弦 : sin 余弦 : cos 正切 : tan 余切 : cot 正弦定理 a/sinA = b/sinB =c/sinC = 2r ...
- ZuulFilter
在服务网关中定义过滤器,只需要继承ZuulFilter抽象类,实现其定义的四个抽象函数,就可对请求进行拦截与过滤 过滤器两个功能: 路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入 ...