zoukankan      html  css  js  c++  java
  • vue递归组件的实现

    本文链接:https://blog.csdn.net/weixin_43756060/article/details/87786344
    vue递归实现图片上的多级菜单


    父级组件结构

    <template>
      <div>
        <detail-banner @show="showImgEvent"/>
        <detail-header />
        <common-gallary v-if="showImg" :imgs="imgs" @show="showImgEvent"/>
        <div class="container">
          <detail-list :list="list"/>
        </div>
      </div>
    </template>
    
    <script>
    import DetailBanner from './components/Banner'
    import DetailHeader from './components/Header'
    import DetailList from './components/List'
    import CommonGallary from 'common/gallary/Gallary'
    export default {
      components: {
        DetailBanner,
        DetailHeader,
        CommonGallary,
        DetailList
      },
      data () {
        return {
          showImg: false,
          imgs: [
            'https://img1.qunarzz.com/p/tts3/1803/94/28d2b3bc42ef7402.jpg_r_1280x840x90_e87df2c9.jpg',
            'https://img1.qunarzz.com/p/tts1/1803/7a/22c09bdb85651202.jpg_r_1280x840x90_a62d44c2.jpg'
          ],
          list: [{
            title: '成人票',
            children: [{
              title: '成人三馆联票',
              children: [{
                title: '成人三馆联票 - 某一连锁店销售'
              }]
            }, {
              title: '成人五馆联票'
            }]
          }, {
            title: '学生票'
          }, {
            title: '儿童票'
          }, {
            title: '特惠票'
          }]
        }
      },
      methods: {
        showImgEvent (status) {
          this.showImg = status
        }
      }
    }
    </script>
    
    <style lang="stylus" scoped></style>

    列表子组件

    <template>
    <div>
      <div class="item" v-for="(item, index) of list" :key="index">
        <div class="itemTitle border-bottom">
          <span class="itemIcon"></span>
          {{ item.title }}
        </div>
        <!-- 当数据中有children属性时,对组件本身进行循环递归 -->
        <div v-if="item.children" class="itemChildren">
          <detail-list :list="item.children"/>
        </div>
      </div>
    </div>
    </template>
    
    <script>
    export default {
      name: 'DetailList',
      props: {
        list: Array
      }
    }
    </script>
    
    <style scoped lang="stylus">
      .itemIcon
        display inline-block
        background-image url(//s.qunarzz.com/vacation_react/detail/better_product.png)
        background-size 100% 100%
        width 66px
        height 20px
        margin-right 10px
      .itemTitle
        line-height 80px
        font-size 32px
        padding 0 20px
      .itemChildren
        padding 0 20px
    </style>
  • 相关阅读:
    phpstrom+xdebug+chrome+postman调试工具搭建
    Docker常用命令
    使用nginx+docker配置https负载均衡
    LVS三种模式的区别及负载均衡算法
    ELK Betas 6.0安装及使用
    Excel从低级到中级
    我回来了,哈哈
    刷电信版s710d卡在htc开机画面的解决办法
    基于cocos2d-android-1的FlyppyBird
    利息?hii
  • 原文地址:https://www.cnblogs.com/lst619247/p/11446243.html
Copyright © 2011-2022 走看看