解决vue中使用swiper插件问题及swiper在vue中的用法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了解决vue中使用swiper插件问题及swiper在vue中的用法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2506字,纯文字阅读大概需要4分钟。
内容图文
Swiper简介
Swiper常用于移动端网站的内容触摸滑动。
Swiper是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端。
Swiper能实现触屏焦点图、触屏Tab切换、触屏多图切换等常用效果。
Swiper开源、免费、稳定、使用简单、功能强大,是架构移动终端网站的重要选择!
解决vue中使用swiper插件,在引入swiper插件后,发现无法正常运行问题
这次我们模拟从后台取下数据,然后数据绑定在swiper标签中。
<template> <div class="homePage"> <abc></abc> <div id="banner"> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide" v-for="items in swiper" ><a href=""><img :src=" rel="external nofollow" items.activity.img"></a></div> </div> <div class="swiper-pagination"></div> </div> </div> </div> </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)
接着在需要用到的组件里结构中插入代码
<div class="banner"> <swiper :options="swiperOption"> <swiper-slide v-for="items in allData.bannerphoto" key="items"> <img :src="items" alt=""> </swiper-slide> <div class="swiper-pagination" slot="pagination"></div> </swiper> <div class="jc"></div> </div>
然后在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是轮播图切换的方式 更改属性可切换轮播模式。
总结
以上所述是小编给大家介绍的解决vue中使用swiper插件问题及swiper在vue中的用法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
内容总结
以上是互联网集市为您收集整理的解决vue中使用swiper插件问题及swiper在vue中的用法全部内容,希望文章能够帮你解决解决vue中使用swiper插件问题及swiper在vue中的用法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。