zoukankan      html  css  js  c++  java
  • Vue实现二级菜单的显示与隐藏

    <html>
      <head>
        <title>Vue实现二级菜单的显示与隐藏</title>
        <script src="vue.js"></script>
        <style type="text/css">
         *{
             padding: 0;
             margin: 0;      
             font-size: 14px;    
          }  
          
         ul{      
              200px;      
             height: auto;   
         } 
    
         h2{      
             background: green;      
             border: 1px solid #fff;      
             color: #fff;      
             height: 30px;      
             line-height: 30px;      
             text-indent: 24px;    
         }  
    
          h3{      
             background: #999;      
             height: 24px;      
             line-height: 24px;      
             border: 1px solid #fff;      
             text-indent: 50px;    
         }       
        </style>
      </head>
      <body>
        <div id="nav">
          <ul>
            <li v-for="item in items">
              <h2 @click="showToggle(item)">{{ item.name }}</h2>
              <ul v-if="item.isSubshow">
                <li v-for="subItem in item.subItems">
                  <h3>{{ subItem.name }}</h3>
                </li>
              </ul>
            </li>
          </ul>
        </div>
        <script>
         new Vue({
           el:"#nav",
           data:{
             items:[
               { 
                  name: "Web前端",
                  isSubshow:false,
                  subItems:[
                    {
                      name:"HTML"
                    },
                    {
                      name:"Css"
                    },
                    {
                      name:"JavaScript"
                    }
                  
                  ]
               },
               {
                  name:"写代码的兔子",
                  isSubshow:false,
                  subItems:[
                    {
                      name:"Vue组件"
                    },
                    {
                      name:"Vue实现下拉菜单"
                    },
                    {
                      name:"Vue实现简易留言板"
                    }
                  ]
               }
             ]
           },
           methods:{
             showToggle:function(item){
               item.isSubshow = !item.isSubshow;
             }
           }
         })
        
        </script>
    </body>
    </html>
  • 相关阅读:
    2020软件工程作业 4
    2020软件工程作业 3
    2020软件工程作业 2
    2020软件工程作业 1
    2020软件工程最后一次作业
    2020软件工程第四次作业
    2020软件工程第三次作业
    2020软件工程第二次作业
    2020软件工程第一次作业
    结对第二次作业
  • 原文地址:https://www.cnblogs.com/mica/p/11265307.html
Copyright © 2011-2022 走看看