首页 > 其他 > 详细

Vue实现递归menu

时间:2020-04-02 17:05:49      阅读:74      评论:0      收藏:0      [点我收藏+]
<!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>

 

Vue实现递归menu

原文:https://www.cnblogs.com/lguow/p/12620708.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!