基于vue.js轮播组件vue-awesome-swiper实现轮播图
程序员文章站
2022-06-08 20:03:36
一般做移动端轮播图的时候,最常用的就是swiper插件了,而vue.js也有一个轮播组件vue-awesome-swiper,用法跟swiper相似。
1.安装vie-a...
一般做移动端轮播图的时候,最常用的就是swiper插件了,而vue.js也有一个轮播组件vue-awesome-swiper,用法跟swiper相似。
1.安装vie-awesome-swiper
nam install vue-awesome-swiper --save-dev
2.引用vie-awesome-swiper组件,这里我是用vie-cli创建的项目,在main.js:
import vueawesomeswiper from 'vue-awesome-swiper'; vue.use(vueawesomeswiper) //记得不要忘记这句
3.home.vue下使用
<template> <div> <swiper :options="swiperoption" ref="myswipera"> <!-- 幻灯内容 --> <swiper-slide>slide1</swiper-slide> <swiper-slide>slide2</swiper-slide> <!-- 以下控件元素均为可选 --> <div class="swiper-pagination" slot="pagination"></div> <div class="swiper-button-prev" slot="button-prev"></div> <div class="swiper-button-next" slot="button-next"></div> <div class="swiper-scrollbar" slot="scrollbar"></div> </swiper> </div> </template> <script> export default{ data(){ return { swiperoption: { // 所有配置均为可选(同swiper配置) notnexttick: true, autoplay: 3000, grabcursor : true, setwrappersize :true, autoheight: true, pagination : '.swiper-pagination', paginationclickable :true, prevbutton:'.swiper-button-prev', nextbutton:'.swiper-button-next', scrollbar:'.swiper-scrollbar', mousewheelcontrol : true, observeparents:true, ontransitionstart(swiper){ console.log(swiper) } } } }, computed: { swiper() { return this.$refs.myswipera.swiper } }, mounted() { console.log("每次切换都会触发我"); this.swiper.slideto(3, 1000, false) } } </script>
以上所述是小编给大家介绍的基于vue.js轮播组件vue-awesome-swiper实现轮播图,希望对大家有所帮助
上一篇: 中联通酝酿成立云计算公司