vue+swiper實(shí)現(xiàn)側(cè)滑菜單效果
本文實(shí)例為大家分享了vue swiper實(shí)現(xiàn)側(cè)滑菜單效果的具體代碼,供大家參考,具體內(nèi)容如下
先上效果圖:

這個(gè)左右滑動(dòng)以及上下滑動(dòng)主要使用了Swiper的輪播功能,首先是該自定義組件的代碼:
<template>
<div class="s-slider">
<swiper :options="horizontalSwiperOptions" ref="horizontalSwiper">
<swiper-slide class="left" ref="left" v-bind:style="{'background':getRandomColor()}">
<slot name="left"></slot>
</swiper-slide>
<swiper-slide class="content">
<swiper :options="verticalSwiperOptions" ref="verticalSwiper">
<swiper-slide class="top" ref="top" v-bind:style="{'background':getRandomColor()}">
<slot name="top"></slot>
</swiper-slide>
<swiper-slide class="content" ref="content" v-bind:style="{'background':getRandomColor()}">
<slot name="content"></slot>
</swiper-slide>
<swiper-slide class="bottom" ref="bottom" v-bind:style="{'background':getRandomColor()}">
<slot name="bottom"></slot>
</swiper-slide>
</swiper>
</swiper-slide>
<swiper-slide class="right" ref="right" v-bind:style="{'background':getRandomColor()}">
<slot name="right"></slot>
</swiper-slide>
</swiper>
</div>
</template>
<script>
import {swiper, swiperSlide, swiperWraper} from 'vue-awesome-swiper'
export default {
name: "s-slider",
props: ['leftWidth','rightWidth','topHeight','bottomHeight'],
data() {
return {
horizontalSwiperOptions: {
slidesPerView: 'auto',
initialSlide: 0,
direction: 'horizontal'
},
verticalSwiperOptions:{
slidesPerView: 'auto',
initialSlide: 0,
direction: 'vertical'
}
}
},
mounted() {
setTimeout(() => {
this._initMenuWidth();
}, 20);
},
methods: {
_initMenuWidth() {
this.$refs.left.$el.style.width = this.leftWidth;
this.$refs.right.$el.style.width = this.rightWidth;
this.$refs.top.$el.style.height = this.topHeight;
this.$refs.bottom.$el.style.height = this.bottomHeight;
this.horizontalSwiper.updateSlides();
this.horizontalSwiper.slideTo(1, 1000, false);
this.verticalSwiper.updateSlides();
this.verticalSwiper.slideTo(1, 1000, false);
},
/*獲取隨機(jī)顏色*/
getRandomColor() {
return "#" + ("00000" + ((Math.random() * 16777215 + 0.5) >> 0).toString(16)).slice(-6);
}
},
computed: {
horizontalSwiper() {
return this.$refs.horizontalSwiper.swiper;
},
verticalSwiper(){
return this.$refs.verticalSwiper.swiper;
}
}
}
</script>
<style scoped lang="scss">
@import "src/base/css/public/variable.scss";
@import "swiper/dist/css/swiper.css";
.s-slider {
height: 100%;
color: white;
.swiper-container {
@include fill-with-parent
}
}
</style>
該組件自定義了四個(gè)屬性,分別是左右側(cè)滑菜單的寬度,上下滑動(dòng)菜單的高度,leftWdith、rightWidth、topHeight、bottomHeight,然后用了一個(gè)橫向的輪播用來(lái)存放左滑菜單,中間內(nèi)容,右滑菜單,然后在中間內(nèi)容又放了一個(gè)縱向的輪播用來(lái)放置上滑菜單,內(nèi)容以及下滑菜單,具體思路就是這樣。在組件掛載的時(shí)候,需要根據(jù)父組件傳入的數(shù)值去初始化四個(gè)菜單的寬高,初始化完畢寬高之后,還要調(diào)用swiper本身的updateSlides更新所有的slides,不然滑動(dòng)的時(shí)候,還是按照沒設(shè)置之前的寬高進(jìn)行滑動(dòng)。在父組件中調(diào)用:
<s-slider leftWidth="200px" rightWidth="300px" topHeight="100px" bottomHeight="150px"> <div slot="left"> left </div> <div slot="content"> Content </div> <div slot="right"> right </div> <div slot="top"> top </div> <div slot="bottom"> bottom </div> </s-slider>
不要忘了在父組件中還要引入這個(gè)vue組件。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue2中引用及使用 better-scroll的方法詳解
- 詳解 vue better-scroll滾動(dòng)插件排坑
- vue2.0 better-scroll 實(shí)現(xiàn)移動(dòng)端滑動(dòng)的示例代碼
- vue使用 better-scroll的參數(shù)和方法詳解
- vue利用better-scroll實(shí)現(xiàn)輪播圖與頁(yè)面滾動(dòng)詳解
- vue滾動(dòng)軸插件better-scroll使用詳解
- vue 下列表側(cè)滑操作實(shí)例代碼詳解
- Vue側(cè)滑菜單組件——DrawerLayout
- vue中使用better-scroll實(shí)現(xiàn)滑動(dòng)效果及注意事項(xiàng)
相關(guān)文章
Vue中的數(shù)據(jù)驅(qū)動(dòng)解釋
這篇文章主要為大家介紹了Vue中的數(shù)據(jù)驅(qū)動(dòng)解釋,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
Vue項(xiàng)目中new?Vue()和export?default{}的區(qū)別說明
這篇文章主要介紹了Vue項(xiàng)目中new?Vue()和export?default{}的區(qū)別說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
vue中beforeRouteLeave實(shí)現(xiàn)頁(yè)面回退不刷新的示例代碼
這篇文章主要介紹了vue中beforeRouteLeave實(shí)現(xiàn)頁(yè)面回退不刷新的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
vue按需加載組件webpack require.ensure的方法
本篇文章主要介紹了vue按需加載組件webpack require.ensure的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
VUE項(xiàng)目中調(diào)用高德地圖的全流程講解
這篇文章主要介紹了VUE項(xiàng)目中調(diào)用高德地圖的全流程講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08

