这篇文章主要为大家详细介绍了vue引入swiper插件的使用实例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!
本文介绍了vue引入swiper插件,分享给大家,希望对大家有帮助
代码如下:
$ npm install vue
代码如下:
# 全局安装 vue-cli
$ npm install -g vue-cli
$ cd my-project
$ npm install
$ npm run dev
上面这些就是安装好vue项目,最主要的就是下面的步骤
安装runtime:
终端命令:npm install babel-runtime
修改.eslintrc.js文件如下:
代码如下:
// http://eslint.org/docs/user-guide/configuring
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true,
},
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
},
'globals': {
"Swiper": true
} //这个地方是新加入的 全局注入
}
代码如下:
<div v-on:mouseenter="stopPlay()" v-on:mouseleave="play()" class="swiper-container gallery-top swiper-container-horizontal">
<div class="swiper-wrapper">
<div v-for="value in lbt" class="swiper-slide swiper-slide-next" style="width: 100%; margin-right: 10px;" v-bind:style="{backgroundImage: 'url(' + value.imgs + ')'}"></div>
</div>
<div class="swiper-button-next swiper-button-white"></div>
<div class="swiper-button-prev swiper-button-white swiper-button-disabled"></div>
</div>
<div class="swiper-container gallery-thumbs swiper-container-horizontal">
<div class="swiper-wrapper">
<div v-for="value in lbt" class="swiper-slide swiper-slide-next" style="margin-right: 10px;" v-bind:style="{backgroundImage: 'url(' + value.imgs + ')'}"></div>
</div>
</div>
代码如下:
import Swiper from '../../static/swiper-3.4.2.min.js'
let galleryTop
let galleryThumbs
export default {
name: 'main',
data () {
return {
lbt: [
{
'imgs': '../static/product/lbt1.jpg'
}, {
'imgs': '../static/product/lbt2.jpg'
}, {
'imgs': '../static/product/lbt3.jpg'
}
]
}
},
mounted () {
this.lunbo()
},
methods: {
lunbo () {
galleryTop = new Swiper('.gallery-top', {
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
spaceBetween: 10,
grabCursor: true,
initialSlide: 1,
autoplayDisableOnInteraction: false
})
galleryThumbs = new Swiper('.gallery-thumbs', {
spaceBetween: 10,
autoplay: 4000,
initialSlide: 1,
centeredSlides: true,
slidesPerView: 'auto',
touchRatio: 0.2,
slideToClickedSlide: true,
autoplayDisableOnInteraction: false,
grabCursor: true
})
galleryTop.params.control = galleryThumbs
galleryThumbs.params.control = galleryTop
},
stopPlay () {
galleryTop.stopAutoplay()
galleryThumbs.stopAutoplay()
},
play () {
galleryTop.startAutoplay()
galleryThumbs.startAutoplay()
}
}
}
代码如下:
@import url("../assets/swiper-3.4.2.min.css");
.gallery-top{
height:32rem;
width:100%;
}
.gallery-thumbs{
height:20%;
box-sizing:border-box;
padding:10px 0;
background: rgba(0, 0, 0, 0.4);
cursor: pointer;
}
.gallery-thumbs .swiper-slide{
width:30%;
height:6rem;
opacity:0.3;
}
.gallery-thumbs .swiper-slide-active{
opacity:1;
}
.swiper-slide{
background-size: 100% 160%;
-webkit-background-size: 100% 160%;
}
这里还有一个很重要的问题,在模板里面设置背景图,写法应该是
代码如下:
v-bind:style="{backgroundImage: 'url(' + value.imgs + ')'}"
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持四海网。
本文来自:http://www.q1010.com/184/3271-0.html
注:关于vue引入swiper插件的使用实例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:vue.js
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。