Skip to content

Instantly share code, notes, and snippets.

@mdunbavan
Created February 24, 2017 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdunbavan/f4ec70c5691c54870a128d31bd56b8b2 to your computer and use it in GitHub Desktop.
Save mdunbavan/f4ec70c5691c54870a128d31bd56b8b2 to your computer and use it in GitHub Desktop.
Swiper Vue Plugin
const ListComp = {
template: `
<div class="wrapper grid" id="start-parralex">
<div class="grid__item large--one-third medium--one-whole no-padding" v-for="(key, index) in productsOrderBy">
<swiper :options="swiperOption">
<swiper-slide v-for="slide in swiperSlides">I'm Slide {{ slide }}</swiper-slide>
<div class="swiper-pagination" slot="pagination"></div>
</swiper>
<div v-if="productsOrderBy[index].vendor">
<router-link :to="'/products/'+ index" active-class="active" class="product grow">
<div class="inner-container relative">
<div class="pad-normal absolute top-0 left-0 z-2 large--one-whole product-color product-info">
<p class="univers uppercase smaller body-size">
Shop
</p>
<p class="lyon-text">{{productsOrderBy[index].title}}</p>
<p class="univers uppercase smaller body-size">
Buy now
</p>
</div>
<a href="#" class="slider-arrows prev-slider"></a>
<div class="z-1 relative gallery" v-bind:id="productsOrderBy[index].id">
<div v-for="image in productsOrderBy[index].images">
<img class="scale-with-grid archives-image" v-bind:src="image.src" v-bind:alt="image.id">
</div>
</div>
<div class="z-1 relative slider" style="display: none;" v-bind:id="productsOrderBy[index].id">
<div v-for="image in productsOrderBy[index].images">
<img class="scale-with-grid archives-image" v-bind:src="image.src" v-bind:alt="image.id">
</div>
</div>
<a href="#" class="slider-arrows next-slider"></a>
</div>
<transition
v-if="$route.params.id == index"
appear
name="slide-fade">
<router-view :key="$route.params.id"></router-view>
</transition>
</router-link>
</div>
<div v-else>
<div class="inner-container relative blog-index__block" v-bind:style="{color: productsOrderBy[index].title}">
<div class="pad-normal z-1 large--one-whole">
<p class="univers uppercase smaller body-size">
Influence
</p>
<p class="lyon-text">
{{ productsOrderBy[index].title }}
</p>
</div>
<img class="scale-with-grid archives-image" v-bind:src="productsOrderBy[index].image.src">
</div>
</div>
</div>
</div>
`,
data() {
return {
fade: true,
swiperOption: {
// 所有配置均为可选(同Swiper配置)
// NotNextTick is a component's own property, and if notNextTick is set to true, the component will not instantiate the swiper through NextTick, which means you can get the swiper object the first time (if you need to use the get swiper object to do what Things, then this property must be true)
// notNextTick是一个组件自有属性,如果notNextTick设置为true,组件则不会通过NextTick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象(假如你需要使用获取swiper对象来做什么事,那么这个属性一定要是true)
notNextTick: true,
autoplay: 3000,
direction : 'vertical',
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,
// if you need use plugins in the swiper, you can config in here like this
// 如果自行设计了插件,那么插件的一些配置相关参数,也应该出现在这个对象中,如下debugger
debugger: true,
// swiper callbacks
// swiper的各种回调函数也可以出现在这个对象中,和swiper官方一样
onTransitionStart(swiper){
console.log(swiper)
}
},
swiperSlides: [1, 2, 3, 4, 5]
};
},
computed: {
productsOrderBy() {
//return this.store.getters.productsOrdered;
return this.$store.getters.productsOrdered;
},
products() {
return this.$store.state.products;
},
posts() {
return this.$store.state.posts;
}
},
mounted: function() {
this.unslick();
},
methods: {
unslick(event){
$('.slider').hide();
$('.gallery').show();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment