vue實現(xiàn)輪播圖片
更新時間:2022年07月14日 17:02:10 作者:吾行遠方
這篇文章主要為大家詳細介紹了vue實現(xiàn)簡單的輪播圖片,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue實現(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" >
?? ? ? ? ? ? ? ? ? ? ? //點擊圖片跳到哪里,這里跳到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>
?? ? ? ? ? ? ? ? ? <!-- 常見的小圓點 -->
?? ? ? ? ? ? ? ? ? <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: {
?? ? ? ? ? ? ? ? ? ?//是一個組件自有屬性,如果notNextTick設(shè)置為true,組件則不會通過NextTick來實例化swiper,也就意味著你可以在第一時間獲取到swiper對象,假如你需要剛加載遍使用獲取swiper對象來做什么事,那么這個屬性一定要是true
?? ? ? ? ? ? ? ? ? ?notNextTick: true,
?? ? ? ? ? ? ? ? ? ?//循環(huán),而不是每次都突然回到第一個
?? ? ? ? ? ? ? ? ? ?loop: true,
?? ? ? ? ? ? ? ? ? ?//設(shè)定初始化時slide的索引,加載頁面時顯示的第幾個,從0開始
?? ? ? ? ? ? ? ? ? ?initialSlide: 0,
?? ? ? ? ? ? ? ? ? ?//自動播放
?? ? ? ? ? ? ? ? ? ?autoplay: {
?? ? ? ? ? ? ? ? ? ? ? ?/*切換輪播圖片的時間,即上次切換成功后到再次需要切換的時間*/
?? ? ? ? ? ? ? ? ? ? ? ?delay: 1500,
?? ? ? ? ? ? ? ? ? ? ? ?stopOnLastSlide: false,
?? ? ? ? ? ? ? ? ? ? ? ?/* 觸摸滑動后是否繼續(xù)輪播 false觸摸后不再點擊繼續(xù)輪播,true觸摸后不再點擊不輪播,停在最后一次頁面*/
?? ? ? ? ? ? ? ? ? ? ? ?disableOnInteraction: false
?? ? ? ? ? ? ? ? ? ?},
?? ? ? ? ? ? ? ? ? ?//滑動速度,時間單位,越小越快,與上面 delay 區(qū)別,speed是完成切換所需時間,delay是切換成功后停留多長時間再切換
?? ? ? ? ? ? ? ? ? ?speed: 800,
?? ? ? ? ? ? ? ? ? ?//滑動方向
?? ? ? ? ? ? ? ? ? ?direction: "horizontal",
?? ? ? ? ? ? ? ? ? ?//小手掌抓取滑動
?? ? ? ? ? ? ? ? ? ?grabCursor: true,
?? ? ? ? ? ? ? ? ? ?on: {
?? ? ? ? ? ? ? ? ? ? ? ?//滑動之后回調(diào)函數(shù)
?? ? ? ? ? ? ? ? ? ? ? ?slideChangeTransitionStart: function() {
?? ? ? ? ? ? ? ? ? ? ? ? ? ?/* realIndex為滾動到當(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>以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue中beforeRouteLeave實現(xiàn)頁面回退不刷新的示例代碼
這篇文章主要介紹了vue中beforeRouteLeave實現(xiàn)頁面回退不刷新的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
element-ui?form表單的動態(tài)rules校驗功能實現(xiàn)
在vue項目中,有時候可能會用到element-ui?form表單的動態(tài)rules校驗,這篇文章主要介紹了element-ui form表單的動態(tài)rules校驗,我們可以巧妙的運用element-ui form表單里面form-item的校驗規(guī)則來處理,本文結(jié)合實例代碼介紹的非常詳細,需要的朋友可以參考下2023-07-07
vue腳手架創(chuàng)建項目時報catch錯誤及解決
這篇文章主要介紹了vue腳手架創(chuàng)建項目時報catch錯誤及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01
vue中使用animate.css實現(xiàn)炫酷動畫效果
這篇文章主要介紹了vue中使用animate.css實現(xiàn)動畫效果,我們使用它,只需要寫很少的代碼,就可以實現(xiàn)非常炫酷的動畫效果,感興趣的朋友跟隨小編一起看看吧2022-04-04
vue中用js如何實現(xiàn)循環(huán)可編輯表格
這篇文章主要介紹了vue中用js如何實現(xiàn)循環(huán)可編輯表格,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
vue Cli 環(huán)境刪除與重裝教程 - 版本文檔
這篇文章主要介紹了vue Cli 環(huán)境刪除與重裝教程 - 版本文檔,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09

