最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue實(shí)現(xiàn)可復(fù)用輪播組件的方法

 更新時(shí)間:2022年07月14日 15:38:23   作者:whiteplayer  
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)可復(fù)用輪播組件的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文用vue簡單的實(shí)現(xiàn)了一個輪播圖的基礎(chǔ)功能,并抽離出來作為一個公共組件,方便復(fù)用

html和js部分

<template>
? <div
? ? class="img-box"
? ? ref="img-box"
? ? :style="{width: styles.width, height: styles.height}"
? >
? ? <div v-for="(item, index) in imgList"
? ? ? ? ?:key="index"
? ? ? ? ?class="img-item"
? ? ? ? ?:ref="'img-item-' + index"
? ? ? ? ?:class="{'active': index === active}"
? ? >
? ? ? <img
? ? ? ? :src="item"
? ? ? ? style="width:100%"
? ? ? ? :style="{height: styles.height}"
? ? ? />
? ? </div>
? ? <div
? ? ? class="img-position"
? ? ? v-if="isShowPosition"
? ? >
? ? ? <template v-for="(item, index) in imgList">
? ? ? ? <span :key="index"
? ? ? ? ? ? ? class="img-position-item"
? ? ? ? ? ? ? :ref="'img-position-' + index"
? ? ? ? ? ? ? :class="[
? ? ? ? ? ? ? ? {'active': index === active},
? ? ? ? ? ? ? ? isCircle ? 'circle' : '',
? ? ? ? ? ? ? ? isNums ? 'nums' : ''
? ? ? ? ? ? ? ]"
? ? ? ? ? ? ? @click="clickSpan(index)"
? ? ? ? >
? ? ? ? ? {{isNums ? index + 1 : ''}}
? ? ? ? </span>
? ? ? </template>
? ? </div>
? ? <div
? ? ? class="left-btn"
? ? ? v-if="isShowLeftOrRightBtn"
? ? ? @click="clickBtn('left')"
? ? >
? ? ? <i class="iconfont roll-zuo"></i>
? ? </div>
? ? <div
? ? ? class="right-btn"
? ? ? v-if="isShowLeftOrRightBtn"
? ? ? @click="clickBtn('right')"
? ? >
? ? ? <i class="iconfont roll-you"></i>
? ? </div>
? </div>
</template>

<script>
export default {
? name: 'Roll',
? props: {
? ? imgList: { // 圖片列表 src數(shù)組
? ? ? type: Array,
? ? ? default: () => []
? ? },
? ? isShowPosition: { // 是否顯示下方小圓點(diǎn)
? ? ? type: Boolean,
? ? ? default: true
? ? },
? ? positionInner: { // 圓點(diǎn)內(nèi)容
? ? ? type: String,
? ? ? default: 'circle' // 默認(rèn)圓點(diǎn),可選值 circle => 圓點(diǎn) num => 數(shù)字 both => 圓點(diǎn)+數(shù)字
? ? },
? ? isShowLeftOrRightBtn: { // 是否顯示左右按鈕
? ? ? type: Boolean,
? ? ? default: true
? ? },
? ? duration: { // 切換間隔
? ? ? type: [Number, String],
? ? ? default: 3000
? ? },
? ? styles: { // 自定義輪播圖片寬高 默認(rèn)500*300
? ? ? type: Object,
? ? ? default: () => {
? ? ? ? return {
? ? ? ? ? width: '500px',
? ? ? ? ? height: '300px'
? ? ? ? }
? ? ? }
? ? }
? },
? data () {
? ? return {
? ? ? active: 0, // 當(dāng)前輪播圖片
? ? ? timer: null // 定時(shí)器
? ? }
? },
? computed: {
? ? isCircle () {
? ? ? return ['circle', 'both'].includes(this.positionInner)
? ? },
? ? isNums () {
? ? ? return ['num', 'both'].includes(this.positionInner)
? ? }
? },
? updated () {
? ? if (this.timer) this.clearTimer()
? ? this.setTimer()
? },
? created () {
? ? this.setTimer()
? },
? methods: {
? ? clickSpan (index) {
? ? ? this.clearTimer()
? ? ? this.active = index
? ? },
? ? clickBtn (arg) {
? ? ? this.clearTimer()
? ? ? if (arg === 'left') {
? ? ? ? this.active = this.active - 1 < 0 ? this.imgList.length - 1 : this.active - 1
? ? ? } else {
? ? ? ? this.active = this.active + 1 === this.imgList.length ? 0 : this.active + 1
? ? ? }
? ? ? this.setTimer()
? ? },
? ? setTimer () {
? ? ? this.timer = setInterval(() => {
? ? ? ? this.clickBtn('right')
? ? ? }, Number(this.duration))
? ? },
? ? clearTimer () {
? ? ? clearInterval(this.timer)
? ? ? this.timer = null
? ? }
? }
}
</script>

css樣式部分

<style scoped>
@import url('//at.alicdn.com/t/font_1451815_senarwrqu6.css');
* {
? margin: 0;
? padding: 0;
}
.img-box {
? position: relative;
? margin: 0 auto;
}
.img-item {
? height: 100%;
? width: 100%;
? opacity: 0;
? position: absolute;
? top: 0;
? right: 0;
? left: 0;
? bottom: 0;
? z-index: -5;
? text-align: center;
}
.img-item.active {
? z-index: 0;
? opacity: 1;
? transition: .3s;
}
.img-position {
? position: absolute;
? bottom: 5px;
? left: 50%;
? display: flex;
? transform: translate(-50%, 0);
}
.img-position-item {
? display: inline-block;
? width:10px;
? height:10px;
? box-sizing: border-box;
? cursor: pointer;
}
.img-position-item.circle {
? border-radius: 50%;
? border: 1px solid #606266;
}
.img-position-item.nums {
? width: 18px;
? height: 18px;
? display: flex;
? justify-content: center;
? align-items: center;
? color: #606266;
? font-size:14px;
}
.img-position-item:hover, .img-position-item.active {
? border-color: #d1d2d3;
? color: #d1d2d3;
? transition: .3s;
}
.img-position-item + .img-position-item {
? margin-left: 10px;
}
.left-btn, .right-btn {
? position: absolute;
? top: 50%;
? bottom: 0;
? width: 20px;
? height: 30px;
? display: flex;
? justify-content: center;
? align-items: center;
? cursor: pointer;
? color: #d1d2d3;
? font-size: 20px;
? transform: translate(0, -50%);
}
.left-btn:hover, .right-btn:hover {
? color: #fff;
? transition: .3s;
}
.left-btn {
? left: 5px;
}
.right-btn {
? right: 5px;
}
</style>

只是簡單的實(shí)現(xiàn)了一個輪播圖比較基礎(chǔ)的部分,之前用原生寫了一遍,現(xiàn)在用vue寫一遍作為一個組件,也還不錯。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue實(shí)現(xiàn)鍵盤輸入支付密碼功能

    vue實(shí)現(xiàn)鍵盤輸入支付密碼功能

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)鍵盤輸入支付密碼功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • 解決在vue項(xiàng)目中,發(fā)版之后,背景圖片報(bào)錯,路徑不對的問題

    解決在vue項(xiàng)目中,發(fā)版之后,背景圖片報(bào)錯,路徑不對的問題

    下面小編就為大家分享一篇解決在vue項(xiàng)目中,發(fā)版之后,背景圖片報(bào)錯,路徑不對的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • vue-cli3全面配置詳解

    vue-cli3全面配置詳解

    這篇文章主要介紹了vue-cli3全面配置詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • vue3.x項(xiàng)目降級到vue2.7的解決方案

    vue3.x項(xiàng)目降級到vue2.7的解決方案

    Vue2.7是Vue2.x的最終次要版本,下面這篇文章主要給大家介紹了關(guān)于vue3.x項(xiàng)目降級到vue2.7的解決方案,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-03-03
  • Vue-CLI3.x 設(shè)置反向代理的方法

    Vue-CLI3.x 設(shè)置反向代理的方法

    這篇文章主要介紹了Vue-CLI3.x 設(shè)置反向代理的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • 解決axios發(fā)送post請求返回400狀態(tài)碼的問題

    解決axios發(fā)送post請求返回400狀態(tài)碼的問題

    今天小編就為大家分享一篇解決axios發(fā)送post請求返回400狀態(tài)碼的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • vue3實(shí)現(xiàn)ai聊天對話框功能

    vue3實(shí)現(xiàn)ai聊天對話框功能

    這篇文章主要介紹了vue3實(shí)現(xiàn)ai聊天對話框功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧
    2024-12-12
  • Vue2?的?diff?算法規(guī)則原理詳解

    Vue2?的?diff?算法規(guī)則原理詳解

    這篇文章主要介紹了Vue2的diff算法規(guī)則原理詳解,diff?算法,就是通過比對新舊兩個虛擬節(jié)點(diǎn)不一樣的地方,針對那些不一樣的地方進(jìn)行新增或更新或刪除操作。接下來我們詳細(xì)介紹節(jié)點(diǎn)更新的過程
    2022-06-06
  • vue element實(shí)現(xiàn)將表格單行數(shù)據(jù)導(dǎo)出為excel格式流程詳解

    vue element實(shí)現(xiàn)將表格單行數(shù)據(jù)導(dǎo)出為excel格式流程詳解

    這篇文章主要介紹了vue element實(shí)現(xiàn)將表格單行數(shù)據(jù)導(dǎo)出為excel格式流程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-12-12
  • 創(chuàng)建和運(yùn)行Vue.js項(xiàng)目方法demo

    創(chuàng)建和運(yùn)行Vue.js項(xiàng)目方法demo

    這篇文章主要為大家介紹了創(chuàng)建和運(yùn)行Vue.js項(xiàng)目方法demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12

最新評論

灵丘县| 富锦市| 巴南区| 鄂托克旗| 琼结县| 盐山县| 玛多县| 丘北县| 凤山县| 白水县| 青州市| 隆林| 黄山市| 准格尔旗| 康乐县| 苗栗市| 河津市| 黄陵县| 郴州市| 手游| 县级市| 富阳市| 吴旗县| 长沙市| 沙河市| 湖口县| 扶绥县| 开原市| 安图县| 茂名市| 昭通市| 五莲县| 阳曲县| 罗源县| 武鸣县| 扬州市| 龙岩市| 江都市| 宜阳县| 上饶市| 温州市|