首页 / VUE / swiper插件在vue中的使用技巧
swiper插件在vue中的使用技巧
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了swiper插件在vue中的使用技巧,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2605字,纯文字阅读大概需要4分钟。
内容图文
![swiper插件在vue中的使用技巧](/upload/InfoBanner/zyjiaocheng/293/deb0f8ad328c4ad3bd6dbcd7efa57b4c.jpg)
Swiper简介
Swiper常用于移动端网站的内容触摸滑动。
Swiper是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端。
Swiper能实现触屏焦点图、触屏Tab切换、触屏多图切换等常用效果。
Swiper开源、免费、稳定、使用简单、功能强大,是架构移动终端网站的重要选择!
解决vue中使用swiper插件,在引入swiper插件后,发现无法正常运行问题
这次我们模拟从后台取下数据,然后数据绑定在swiper标签中。
<template> <p class="homePage"> <abc></abc> <p id="banner"> <p class="swiper-container"> <p class="swiper-wrapper"> <p class="swiper-slide" v-for="items in swiper" ><a href=""><img :src=" rel="external nofollow" items.activity.img"></a></p> </p> <p class="swiper-pagination"></p> </p> </p> </p> </template> <script> import Swiper from "../../static/js/swiper-3.4.0.min.js"; import header from 'components/header.vue'; export default { components : { abc : header }, data(){ return { swiper:"" } }, mounted(){ this.$http.get("http://www.vrserver.applinzi.com/aixianfeng/apihome.php").then(function(res){ this.swiper=res.data.data.slide; var mySwiper = new Swiper('.swiper-container', { autoplay: 2000,//可选选项,自动滑动 //分页器 pagination : '.swiper-pagination', paginationClickable :true, observer: true }) }) } } </script> <style type="text/css"> @import "../../static/css/home.css"; @import "../../static/css/swiper-3.4.0.min.css"; </style>
重点就在mounted()的使用,需要把这些方法都放在 mounted()里使用, mounted()是 vue生命周期钩子 ,你也可以理解为当挂载实例到 DOM完了后,才会触发的而方法。
下面看下swiper在vue中的用法
首先通过npm i vue-awesome-swiper --save
来在vue中下载插件
然后再main.js中引入
require('swiper/dist/css/swiper.css') import VueAwesomeSwiper from 'vue-awesome-swiper' Vue.use(VueAwesomeSwiper)
接着在需要用到的组件里结构中插入代码
<p class="banner"> <swiper :options="swiperOption"> <swiper-slide v-for="items in allData.bannerphoto" key="items"> <img :src="items" alt=""> </swiper-slide> <p class="swiper-pagination" slot="pagination"></p> </swiper> <p class="jc"></p> </p>
然后在data中定义轮播图
swiperOption: { pagination: '.swiper-pagination', paginationClickable: true, autoplay: 2500, autoplayDisableOnInteraction: false, loop: false, coverflow: { rotate: 30, stretch: 10, depth: 60, modifier: 2, slideShadows : true } },
此时的coverflow是轮播图切换的方式 更改属性可切换轮播模式。
相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
express默认日志组件morgan的详细介绍
webpack的热模块替换HMR/热更新的具体步奏
以上就是swiper插件在vue中的使用技巧的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的swiper插件在vue中的使用技巧全部内容,希望文章能够帮你解决swiper插件在vue中的使用技巧所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。