Vue-Awesome-Swiper(Vue使用Swiper)

Vue中重点关注绿色字体部分

Vue-Awesome-Swiper

Swiper4 component for Vue, support pc and mobile, SPA and SSR.

If you need to roll back to Swiper3, use version v2.6.7.

基于 Swiper4、适用于 Vue 的轮播组件,支持服务端渲染和单页应用。

如果需要回退到 Swiper3,请使用 v2.6.7 版本。

Example

Demo Page

CDN Example

mobile fullpage example code

nuxt.js/ssr example code

Install

CDN

 
  
<link rel="stylesheet" href="path/to/swiper/dist/css/swiper.css"/>
<script type="text/javascript" src="path/to/swiper.js"></script>
<script type="text/javascript" src="path/to/vue.min.js"></script>
<script type="text/javascript" src="path/to/dist/vue-awesome-swiper.js"></script>
<script type="text/javascript">
  Vue.use(window.VueAwesomeSwiper)
script> 

NPM

 
  
npm install vue-awesome-swiper --save

Mount

mount with global

 
  
import Vue from 'vue'
import VueAwesomeSwiper from 'vue-awesome-swiper'
 
// require styles
import 'swiper/dist/css/swiper.css'
 
Vue.use(VueAwesomeSwiper, /* { default global options } */)

mount with component

 
   
// require styles
import 'swiper/dist/css/swiper.css'
 
import { swiper, swiperSlide } from 'vue-awesome-swiper'
 
export default {
  components: {
    swiper,
    swiperSlide
  }
}

mount with ssr

 
   
// If used in nuxt.js/ssr, you should keep it only in browser build environment
if (process.browser) {
  const VueAwesomeSwiper = require('vue-awesome-swiper/dist/ssr')
  Vue.use(VueAwesomeSwiper)
}

custom swiper plugin

 
   
import Swiper from 'swiper'
Swiper.use({
  name: 'pluginName',
  params: {
    pluginSwitch: false,
  },
  on: {
    init() {
      if (!this.params.pluginSwitch) return
      console.log('init')
    },
    // swiper callback...
  }
})

Difference(使用方法的异同)

SSR and the only difference in the use of the SPA:

  • SPA worked by the component, find swiper instance by ref attribute.
  • SSR worked by the directive, find swiper instance by directive arg.
  • Other configurations, events are the same.

SPA

 
   
 

Async data example

 
   
 

SSR

 
   
 

API

Swiper's API and configuration can be used.(Swiper官网中的API及配置均可使用)

  • CN Swiper4 documents
  • EN Swiper4 documents

你可能感兴趣的:(Vue,Swiper)