本文介绍了vue引入swiper插件,分享给大家,希望对大家有帮助
步骤一:安装vue,
$ npm install vue
步骤二:创建vue项目
# 全局安装 vue-cli $ npm install -g vue-cli $ cd my-project $ npm install $ npm run dev
上面这些就是安装好vue项目,最主要的就是下面的步骤
步骤三:下载好swiper相关的js和css,js放在static目录下,css放在assets目录下。
步骤四:
安装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' "Swiper": true
} //这个地方是新加入的 全局注入
}
步骤六:在自己的vue文件中添加轮播图代码
<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 + ')'}"
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“vue引入swiper插件的使用实例”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2025年10月25日
2025年10月25日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]