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中beforeRouteLeave實(shí)現(xiàn)頁面回退不刷新的示例代碼
這篇文章主要介紹了vue中beforeRouteLeave實(shí)現(xiàn)頁面回退不刷新的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
element-ui?form表單的動(dòng)態(tài)rules校驗(yàn)功能實(shí)現(xiàn)
在vue項(xiàng)目中,有時(shí)候可能會(huì)用到element-ui?form表單的動(dòng)態(tài)rules校驗(yàn),這篇文章主要介紹了element-ui form表單的動(dòng)態(tài)rules校驗(yàn),我們可以巧妙的運(yùn)用element-ui form表單里面form-item的校驗(yàn)規(guī)則來處理,本文結(jié)合實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07
vue腳手架創(chuàng)建項(xiàng)目時(shí)報(bào)catch錯(cuò)誤及解決
這篇文章主要介紹了vue腳手架創(chuàng)建項(xiàng)目時(shí)報(bào)catch錯(cuò)誤及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
vue中使用animate.css實(shí)現(xiàn)炫酷動(dòng)畫效果
這篇文章主要介紹了vue中使用animate.css實(shí)現(xiàn)動(dòng)畫效果,我們使用它,只需要寫很少的代碼,就可以實(shí)現(xiàn)非常炫酷的動(dòng)畫效果,感興趣的朋友跟隨小編一起看看吧2022-04-04
vue3移動(dòng)端嵌入pdf的多種方法小結(jié)
這篇文章主要介紹了vue3移動(dòng)端嵌入pdf的多種方法小結(jié),使用embed嵌入有好處也有缺點(diǎn),本文給大家講解的非常詳細(xì),需要的朋友可以參考下2023-10-10
vue中用js如何實(shí)現(xiàn)循環(huán)可編輯表格
這篇文章主要介紹了vue中用js如何實(shí)現(xiàn)循環(huán)可編輯表格,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
Vue使用canvas實(shí)現(xiàn)圖片壓縮上傳
這篇文章主要為大家詳細(xì)介紹了Vue使用canvas實(shí)現(xiàn)圖片壓縮上傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
vue Cli 環(huán)境刪除與重裝教程 - 版本文檔
這篇文章主要介紹了vue Cli 環(huán)境刪除與重裝教程 - 版本文檔,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09

