vue引入swiper插件的使用实例
发布时间 - 2026-01-11 02:24:31 点击率:次本文介绍了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' ? 2 : 0
},
'globals': {
"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 + ')'}"
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
# vue
# swiper插件
# vue引入swiper
# vue引用swiper插件
# vue项目中导入swiper插件的方法
# Vue框架里使用Swiper的方法示例
# vue中引用swiper轮播插件的教程详解
# vue 中swiper的使用教程
# vue使用swiper实现左右滑动切换图片
# 分享vue里swiper的一些坑
# vue调用swiper插件步骤教程(最易理解且详细)
# 放在
# 自己的
# 目录下
# 给大家
# 很重要
# 还有一个
# 最主要
# 大家多多
# 装好
# 应该是
# plugins
# html
# files
# custom
# paren
# rules
# add
# lint
# blob
# master
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
如何在Windows虚拟主机上快速搭建网站?
如何用花生壳三步快速搭建专属网站?
香港网站服务器数量如何影响SEO优化效果?
javascript事件捕获机制【深入分析IE和DOM中的事件模型】
Edge浏览器怎么启用睡眠标签页_节省电脑内存占用优化技巧
Laravel怎么进行数据库事务处理_Laravel DB Facade事务操作确保数据一致性
手机网站制作与建设方案,手机网站如何建设?
Laravel如何生成和使用数据填充?(Seeder和Factory示例)
手机网站制作平台,手机靓号代理商怎么制作属于自己的手机靓号网站?
Laravel如何使用查询构建器?(Query Builder高级用法)
如何在 Telegram Web View(iOS)中防止键盘遮挡底部输入框
,怎么在广州志愿者网站注册?
英语简历制作免费网站推荐,如何将简历翻译成英文?
Laravel如何实现数据导出到CSV文件_Laravel原生流式输出大数据量CSV【方案】
进行网站优化必须要坚持的四大原则
Laravel如何集成Inertia.js与Vue/React?(安装配置)
详解jQuery中的事件
Android实现代码画虚线边框背景效果
Laravel如何实现本地化和多语言支持_Laravel多语言配置与翻译文件管理
Laravel如何使用Livewire构建动态组件?(入门代码)
如何在HTML表单中获取用户输入并用JavaScript动态控制复利计算循环
北京网站制作公司哪家好一点,北京租房网站有哪些?
Claude怎样写约束型提示词_Claude约束提示词写法【教程】
Laravel如何使用Service Provider注册服务_Laravel服务提供者配置与加载
在线制作视频网站免费,都有哪些好的动漫网站?
Laravel如何实现用户注册和登录?(Auth脚手架指南)
Laravel Octane如何提升性能_使用Laravel Octane加速你的应用
phpredis提高消息队列的实时性方法(推荐)
nginx修改上传文件大小限制的方法
在centOS 7安装mysql 5.7的详细教程
微信小程序 闭包写法详细介绍
Laravel如何配置中间件Middleware_Laravel自定义中间件拦截请求与权限校验【步骤】
Laravel如何使用Blade组件和插槽?(Component代码示例)
Laravel怎么防止CSRF攻击_Laravel CSRF保护中间件原理与实践
如何用5美元大硬盘VPS安全高效搭建个人网站?
Laravel的Blade指令怎么自定义_创建你自己的Laravel Blade Directives
想要更高端的建设网站,这些原则一定要坚持!
如何注册花生壳免费域名并搭建个人网站?
Laravel 419 page expired怎么解决_Laravel CSRF令牌过期处理
Laravel如何优雅地处理服务层_在Laravel中使用Service层和Repository层
Laravel怎么设置路由分组Prefix_Laravel多级路由嵌套与命名空间隔离【步骤】
西安市网站制作公司,哪个相亲网站比较好?西安比较好的相亲网站?
如何确保西部建站助手FTP传输的安全性?
linux写shell需要注意的问题(必看)
学生网站制作软件,一个12岁的学生写小说,应该去什么样的网站?
Win11怎么更改系统语言为中文_Windows11安装语言包并设为显示语言
php嵌入式断网后怎么恢复_php检测网络重连并恢复硬件控制【操作】
中山网站推广排名,中山信息港登录入口?
mc皮肤壁纸制作器,苹果平板怎么设置自己想要的壁纸我的世界?
BootStrap整体框架之基础布局组件

