本篇文章給大家分享的是有關使用vueJs怎么實現一個圖片輪播功能,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

carousel.vue
<template>
<div ref="root">
<div class="sliderPanel">
<div v-for="(item,index) in imgArray" class="verticalCenter picbox">
<transition name="slide-fade">
<img : @mouseover="clearAuto" @mouseout="slideAuto" v-show="index===selectIndex" :src="item.url" >
</transition>
</div>
</div>
<div @click="clickLeft" @mouseover="clearAuto" @mouseout="slideAuto" class="arrowLeft verticalCenter horizaCenter">
左移
</div>
<div @click="clickRight" @mouseover="clearAuto" @mouseout="slideAuto" class="arrowRight verticalCenter horizaCenter">
右移
</div>
<div class="sliderBar horizaCenter">
<div v-for="(item,index) in imgArray" @mouseover="clearAuto" @mouseout="slideAuto" @click="setIndex(index)" class="circle" :class="{circleSelected:index===selectIndex}">
</div>
</div>
</div>
</template>
<script>
const SCREEN_WIDTH=document.body.clientWidth//網頁可見區域寬
const SCREEN_HEIGHT=document.body.scrollHeight//網頁正文全文高
var selectIndex=0
var timer=null
export default {
name: "ErCarousel",
data() {
return {
selectIndex:0,
width:'100%',
height:SCREEN_HEIGHT+'px',
top:0,
imgArray:[
{
url:'/src/components/carousel/image/1.jpg',
},
{
url:'/src/components/carousel/image/2.jpg',
},
{
url:'/src/components/carousel/image/3.jpg',
}
]
}
},
methods:{
slideAuto:function () {
var that=this;
timer=setInterval(function(){
that.clickRight();
},3000)
//clearInterval(timer);
},
clearAuto:function(){
clearInterval(timer);
},
clickLeft:function(){
if(this.selectIndex==0){
this.selectIndex=this.imgArray.length-1;
}else{
this.selectIndex--;
}
console.log(this.selectIndex);
},
clickRight:function(){
if(this.selectIndex==this.imgArray.length-1){
this.selectIndex=0;
}else{
this.selectIndex++;
}
},
setIndex:function (index) {
this.selectIndex=index;
}
},
mounted:function(){
this.slideAuto();
}
}
</script>
<style>以上就是使用vueJs怎么實現一個圖片輪播功能,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注創新互聯網站建設公司行業資訊頻道。
另外有需要云服務器可以了解下創新互聯建站www.yijiale78.com,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
當前名稱:使用vueJs怎么實現一個圖片輪播功能-創新互聯
分享網址:http://www.yijiale78.com/article42/diciec.html
成都網站建設公司_創新互聯,為您提供微信公眾號、營銷型網站建設、定制網站、面包屑導航、微信小程序、電子商務
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯