基于之前写的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. spring关于bean的一些配置说明

    <context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean上面的注解.该标签主要向容器中掩式定的注了 AutowiredAnnotati ...

  2. c_ 数据结构_图_邻接矩阵

    程序主要实现了图的深度遍历和广度遍历. #include <stdio.h> #include <stdlib.h> #include <string.h> #de ...

  3. jQuery实现的文字逐行向上间歇滚动效果示例

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. SQL Server - Store procedure 如何返回值

    存储过程 返回值 procedure return values : http://www.cnblogs.com/SunnyZhu/p/5542347.html return.select.outp ...

  5. 给大家介绍一下linux系统高级命令

    输出重定向(mip.0834jl.com) ;覆盖文件内容 回声' 123 ' 测试;覆盖原始内容 回声' 123 ' 测试;原始存在(共存) echo 'ken2 '(www.jl0834.com) ...

  6. 构造流量图+乱搞——cf990F

    /* 结论1:有解的充要条件是所有点权之和为0 结论2:删掉环上的一条边,只要将这个环上的其余边都减去这条边的边权,那么这个图仍是等价的 从原图网络中构造出一棵带权值的树即可,其他边权都设置为0 通过 ...

  7. C/C++语言实现单链表(带头结点)

    彻底理解链表中为何使用二级指针或者一级指针的引用 数据结构之链表-链表实现及常用操作(C++篇) C语言实现单链表,主要功能为空链表创建,链表初始化(头插法),链表元素读取,按位置插入,(有序链表)按 ...

  8. Vue+Iview+Node 登录demo

    1.相关组件安装 axios  iview  js-cookie  crypto-js 2.子父组件传值.监听窗体大小改变.记住密码 .自定义组件(事件 .props) created:实例已经创建完 ...

  9. 基于V8引擎的C++和JS的相互交互

    基于什么原因略! 1. 脚本引擎的基本功能 V8只是一个JS引擎.去除它的特点功能出处,它必须要实现JS引擎的几个基础功能: 脚本执行:脚本可能是一个表达式:一段js代码:或者一个文件执行表达式返回j ...

  10. NOI2001 炮兵阵地 洛谷2704

    题目描述 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P&quo ...