6.7.3旅游网站小项目练习之首页图标区页面布局组件代码

<template>
    <div class="icons">
        <swiper :options="swiperOption">
             <swiper-slide v-for="(page,index) of pages" :key="index">
                <div class="icon" v-for="item of page" :key="item.id">
                    <div class="icon-img-box">
                        <img class="icon-img" :src="item.iconUrl">
                    </div>
                    <p class="icon-text">{{item.text}}</p>
                </div>
            </swiper-slide>
        </swiper>
    </div>
</template> 

<script>
export default {
    name: 'HomeIcons',
    data () {
        return {
            swiperOption:{
                autoplay: false
            },
            iconList: [{
                id: '001',
                iconUrl: 'https://imgs.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
                text: '热门景点'
            },{
                id: '002',
                iconUrl: 'https://imgs.qunarzz.com/piao/fusion/1803/6c/9e54a8540fee0102.png',
                text: '故宫'
            },{
                id: '003',
                iconUrl: 'https://imgs.qunarzz.com/piao/fusion/1803/fa/2548667cb6e902.png',
                text: '动植物园'
            },{
                id: '004',
                iconUrl: 'https://imgs.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
                text: '一日游'
            },{
                id: '005',
                iconUrl: 'https://imgs.qunarzz.com/piao/fusion/1803/67/9a1678221b8e0e02.png',
                text: '古水北镇'
            },{
                id: '006',
                iconUrl: 'https://imgs.qunarzz.com/piao/fusion/1803/76/eb88861d78fb9902.png',
                text: '赏红叶'
            },{
                id: '007',
                iconUrl: 'https://imgs.qunarzz.com/piao/fusion/1803/ab/6f7d6e44963c9302.png',
                text: '泡温泉欢乐谷欢乐谷'
            },{
                id: '008',
                iconUrl: 'https://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/338c5b924c5809e8c7b14f60a953c3e2.png',
                text: '欢乐谷'
            },{
                id: '009',
                iconUrl: 'https://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20197/bf88c62458044ca2ef9d733690eef3fc.png',
                text: '优惠券'
            }]
        }
    },
    computed: {
        pages () {
            const pages=[]
            this.iconList.forEach((item,index)=>{
                const page=Math.floor(index/8)
                if(!pages[page]){
                    pages[page]=[]
                }
                pages[page].push(item)
            })
            return pages
        }
    }
}
</script>

<style lang="stylus" scoped>
    @import '~@/assets/styles/varibles.styl'
    @import '~@/assets/styles/mixins.styl'
    .icons
        height: 0
        overflow: hidden
        padding-bottom: 50%
        .icon
            overflow: hidden
            float: left
            position: relative
            width: 25%
            height: 0
            padding-bottom: 25%
            .icon-img-box
                position: absolute
                left: 0
                top: 0
                right: 0
                bottom: .44rem
                box-sizing: border-box
                padding .1rem
                .icon-img
                    display: block
                    margin: 0 auto
                    height: 100%
            .icon-text
                position: absolute
                left: 0
                right: 0
                bottom: 0
                height: .44rem
                line-height: .44rem
                text-align: center
                color: $darkTextColor
                ellipsis()
</style>

你可能感兴趣的:(前端~Vue的一些学习笔记)