【新手向】要在页面上要作一个轮播图用swiper的话大概有110KB,功能很强大。然而我只想用个轮播的简单效果,不须要加特效。经过搜索,发现有一个饿了么前端出品的轮播swipe,恰好知足个人需求,并且只有11KB左右足够精简。废话很少说,开整...css
一、安装前端
$ npm install vue-swipe
二、在main.js中添加vue
import Vue from 'vue' import App from './App' import routes from './router/router-config' import { Swipe, SwipeItem } from 'vue-swipe' // 加这里 Vue.component('swipe', Swipe) // 加这里 Vue.component('swipe-item', SwipeItem) // 加这里 /* eslint-disable no-new */ new Vue({ el: '#app', components: { App }, template: '<App/>' })
三、在页面xxxx.vue中引用css样式
【注意:不要加scoped,会污染样式,导航的小圆点就不显示了】git
<style> @import 'vue-swipe/dist/vue-swipe.css'; .my-swipe { height: 200px; color: #fff; font-size: 30px; text-align: center; } .slide1 { background-color: #0089dc; color: #fff; } .slide2 { background-color: #ffd705; color: #000; } .slide3 { background-color: #ff2d4b; color: #fff; } </style>
四、在页面xxxx.vue中你须要的位置上写代码github
<swipe class="my-swipe"> <swipe-item class="slide1">1</swipe-item> <swipe-item class="slide2">2</swipe-item> <swipe-item class="slide3">3</swipe-item> </swipe>
五、效果npm
好了,就这样。app