zoukankan      html  css  js  c++  java
  • Vue实现递归menu

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="utf-8">
        <style>
        #app{
            width: 300px;
            overflow: hidden;
        }
        .item{
             margin-left: 30px;
             /* padding-left: 30px; */
             width: 100%;
             
                
        }
        .name {
            background-color: pink;
            border-bottom: 1px solid #333;
            cursor:pointer;
        }
         .name:hover{
             background-color: orange;
         }
        </style>
    </head>
    
    <body>
        <div id="app">
              <list :menus="menus"></list>
        </div>
        <template id="list">
            <div>
                <div v-for="(item,index) in menus" :key="index" class="item">
                    <div class="name">{{item.name}}</div>
                    <child v-if="item.children" :child="item.children"></child>
                </div>
            </div>
        </template>
        <template id="child">
            <div>
                <list :menus="child"></list>
            </div>
        </template>
        <script src="vue.js"></script>
        <script>
        Vue.component("list", {
            props: ['menus'],
            template: "#list",
        })
        Vue.component("child", {
            props: ['child'],
            template: "#child",
        })
        var vm = new Vue({
            el: "#app",
    
            data: {
                menus: [{
                    name: "经济",
                    children: [{
                        name: "如家",
                        children: [{
                            name: "上江路-如家"
                        }, {
                            name: "望江路-如家"
                        }]
                    }, {
                        name: "7天",
                        children: [{
                            name: "长江路-7天"
                        }, {
                            name: "望江路-7天"
                        }]
                    }]
                }]
            },
            mounted: function() {
    
            },
            method: {
    
            }
        })
        </script>
    </body>
    
    </html>
  • 相关阅读:
    MySQL数据库----数据类型
    MySQL数据库----安装
    I2c串行总线组成及其工作原理
    感慨
    液晶操作
    串口通信
    9.19AD和DA操作
    9.19键盘的应用
    9.17键盘的操作
    9.15学习笔记
  • 原文地址:https://www.cnblogs.com/lguow/p/12620708.html
Copyright © 2011-2022 走看看