vue實(shí)現(xiàn)輪播圖片
本文實(shí)例為大家分享了vue實(shí)現(xiàn)輪播圖片的具體代碼,供大家參考,具體內(nèi)容如下
1、效果圖

2、案例
<template>
?? ? ? <section class="body">
?? ? ? ? ? <section class="wrap">
?? ? ? ? ? ? ? <swiper :options="swiperOption" class="swiper-wrap" ?ref="mySwiper" v-if="banner.length!=0">
?? ? ? ? ? ? ? ? ? <swiper-slide v-for="(item,index) in banner" :key="index" >
?? ? ? ? ? ? ? ? ? ? ? //點(diǎn)擊圖片跳到哪里,這里跳到home頁面 item舉例:{img:http://www.***.com/home/images/index_img02.png,url:/home}
?? ? ? ? ? ? ? ? ? ? ? <img :src="item.img" alt="" @click="skip_out_page(item.url)" />
?? ? ? ? ? ? ? ? ? </swiper-slide>
?? ? ? ? ? ? ? ? ? <!-- 常見的小圓點(diǎn) -->
?? ? ? ? ? ? ? ? ? <div class="swiper-pagination" ?v-for="(item,index) in banner" :key="index" slot="pagination" ></div>
?? ? ? ? ? ? ? </swiper>
?? ? ? ? ? </section>
?? ? ? </section>
</template><script>
?? ?export default {
?? ? ? ?data() {
?? ? ? ? ? ?const that = this;
?? ? ? ? ? ?return {
?? ? ? ? ? ? ? ?imgIndex: 1,
?? ? ? ? ? ? ? ?swiperOption: {
?? ? ? ? ? ? ? ? ? ?//是一個(gè)組件自有屬性,如果notNextTick設(shè)置為true,組件則不會(huì)通過NextTick來實(shí)例化swiper,也就意味著你可以在第一時(shí)間獲取到swiper對(duì)象,假如你需要?jiǎng)偧虞d遍使用獲取swiper對(duì)象來做什么事,那么這個(gè)屬性一定要是true
?? ? ? ? ? ? ? ? ? ?notNextTick: true,
?? ? ? ? ? ? ? ? ? ?//循環(huán),而不是每次都突然回到第一個(gè)
?? ? ? ? ? ? ? ? ? ?loop: true,
?? ? ? ? ? ? ? ? ? ?//設(shè)定初始化時(shí)slide的索引,加載頁面時(shí)顯示的第幾個(gè),從0開始
?? ? ? ? ? ? ? ? ? ?initialSlide: 0,
?? ? ? ? ? ? ? ? ? ?//自動(dòng)播放
?? ? ? ? ? ? ? ? ? ?autoplay: {
?? ? ? ? ? ? ? ? ? ? ? ?/*切換輪播圖片的時(shí)間,即上次切換成功后到再次需要切換的時(shí)間*/
?? ? ? ? ? ? ? ? ? ? ? ?delay: 1500,
?? ? ? ? ? ? ? ? ? ? ? ?stopOnLastSlide: false,
?? ? ? ? ? ? ? ? ? ? ? ?/* 觸摸滑動(dòng)后是否繼續(xù)輪播 false觸摸后不再點(diǎn)擊繼續(xù)輪播,true觸摸后不再點(diǎn)擊不輪播,停在最后一次頁面*/
?? ? ? ? ? ? ? ? ? ? ? ?disableOnInteraction: false
?? ? ? ? ? ? ? ? ? ?},
?? ? ? ? ? ? ? ? ? ?//滑動(dòng)速度,時(shí)間單位,越小越快,與上面 delay 區(qū)別,speed是完成切換所需時(shí)間,delay是切換成功后停留多長(zhǎng)時(shí)間再切換
?? ? ? ? ? ? ? ? ? ?speed: 800,
?? ? ? ? ? ? ? ? ? ?//滑動(dòng)方向
?? ? ? ? ? ? ? ? ? ?direction: "horizontal",
?? ? ? ? ? ? ? ? ? ?//小手掌抓取滑動(dòng)
?? ? ? ? ? ? ? ? ? ?grabCursor: true,
?? ? ? ? ? ? ? ? ? ?on: {
?? ? ? ? ? ? ? ? ? ? ? ?//滑動(dòng)之后回調(diào)函數(shù)
?? ? ? ? ? ? ? ? ? ? ? ?slideChangeTransitionStart: function() {
?? ? ? ? ? ? ? ? ? ? ? ? ? ?/* realIndex為滾動(dòng)到當(dāng)前的slide索引值 */
?? ? ? ? ? ? ? ? ? ? ? ? ? ?that.imgIndex= this.realIndex - 1;
?? ? ? ? ? ? ? ? ? ? ? ?},
?? ? ? ? ? ? ? ? ? ?},
?? ? ? ? ? ? ? ? ? ?//分頁器設(shè)置
?? ? ? ? ? ? ? ? ? ?pagination: {
?? ? ? ? ? ? ? ? ? ? ? ?el: ".swiper-pagination",
?? ? ? ? ? ? ? ? ? ? ? ?clickable: true,
?? ? ? ? ? ? ? ? ? ? ? ?type: "bullets"
?? ? ? ? ? ? ? ? ? ?}
?? ? ? ? ? ? ? ?},
?? ? ? ? ? ? ? ?banner: []
?? ? ? ? ? ?}
?? ? ? ?},
?? ? ? ?methods: {
?? ? ? ? ? ?skip_out_page(v) {
?? ? ? ? ? ? ? ?window.location.href = v
?? ? ? ? ? ?},
?? ? ? ? ? ?get_data() {
?? ? ? ? ? ? ? ?this.$http.get('test').then(res => {
?? ? ? ? ? ? ? ? ? ?if(res.data.code == '0000'){
?? ? ? ? ? ? ? ? ? ? ? ?this.banner = res.data.img_info
?? ? ? ? ? ? ? ? ? ?}
?? ? ? ? ? ? ? ?});
?? ? ? ? ? ?}
?? ? ? ?},
?? ? ? ?mounted() {
?? ? ? ? ? ?this.get_data()
?? ? ? ?}
?? ?}
</script><style lang="scss">
?? ?.swiper-wrap{
?? ? ? ?width: 100%;
?? ? ? ?height: 210px;
?? ? ? ?background-color: #fff;
?? ?}
?? ?.swiper-pagination{
?? ? ? ?background: #fff;
?? ?}
?? ?.swiper-pagination-bullet{
?? ? ? ?background: #ccc;
?? ? ? ?width: 10px;
?? ? ? ?height: 10px;
?? ? ? ?opacity: 1;
?? ?}
?? ?.swiper-pagination-bullet-active{
?? ? ? ?background: #00C293;
?? ?}
</style>以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue中進(jìn)行數(shù)據(jù)篩選與搜索功能實(shí)現(xiàn)常用的方法
表格常用功能經(jīng)常有字段篩選、更多字段篩選彈框來過濾出我們所需要的數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于Vue中進(jìn)行數(shù)據(jù)篩選與搜索功能實(shí)現(xiàn)常用的方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12
vue原理Compile從新建實(shí)例到結(jié)束流程源碼
這篇文章主要為大家介紹了vue原理Compile從新建實(shí)例到結(jié)束流程源碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
Vue創(chuàng)建淺層響應(yīng)式數(shù)據(jù)的實(shí)例詳解
這篇文章主要介紹了Vue創(chuàng)建淺層響應(yīng)式數(shù)據(jù)的實(shí)例,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-11-11
Vue+Openlayer實(shí)現(xiàn)圖形的拖動(dòng)和旋轉(zhuǎn)變形效果
Openlayer具有自己的擴(kuò)展插件ol-ext,可以用來實(shí)現(xiàn)圖形的拖拽、旋轉(zhuǎn)、縮放、拉伸、移動(dòng)等操作,本文將主要介紹通過Openlayer實(shí)現(xiàn)圖形的拖動(dòng)和旋轉(zhuǎn),需要的同學(xué)可以學(xué)習(xí)一下2021-11-11
Vue 應(yīng)用中結(jié)合vux使用微信 jssdk的方法
今天小編就為大家分享一篇Vue 應(yīng)用中結(jié)合vux使用微信 jssdk的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08
Vue Router根據(jù)后臺(tái)數(shù)據(jù)加載不同的組件實(shí)現(xiàn)
本文主要介紹了根據(jù)用戶所購(gòu)買服務(wù)的不同,有不同的頁面展現(xiàn)。文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08

