Vue to achieve click on the current unfold function?

topic description

vue implements to click on the current unfold function, and now click all to expand and put away

sources of topics and their own ideas

clipboard.png

related codes

/ / Please paste the code text below (do not replace the code with pictures)

<template>
<div class="left">
  <ul>
    <li></li>
    <li v-for="nav in navList" :key="nav.id" @click="showNav($event)">{{nav.navOne}}
      <i class="iconfont icon-iconfontjiantou"></i>
      <ul class="nav-child" v-show="showTag">
        <li v-for="item in nav.navTwo" :key="item.id">{{item.title}}</li>
      </ul>
    </li>
  </ul>
</div>
</template>

<script>
export default {
  name: "left",
  data:function(){
    return {
      showTag:false,
      navList:[
      {
        navOne:"",
        id:1,
        navTwo:[
          {
            title:"",
            id:1,
          }
        ]
      },
      {
        navOne:"",
        id:2,
        navTwo:[
          {
            title:"",
            id:1
          }
        ]
      },
      {
        navOne:"",
        id:3,
        navTwo:[
          {
            title:"",
            id:1
          },
          {
            title:"",
            id:2
          },
          {
            title:"",
            id:3
          }
        ]
      },
      {
        navOne:"",
        id:4,
        navTwo:[
          {
            title:"",
            id:1
          },
          {
            title:"",
            id:2
          }
        ]
      },
      {
        navOne:"",
        id:5,
        navTwo:[
          {
            title:"",
            id:1
          },
          {
            title:"",
            id:2
          },
          {
            title:"",
            id:3
          },
          {
            title:"",
            id:4
          },
          {
            title:"",
            id:5
          },
          {
            title:"",
            id:6
          },
          {
            title:"",
            id:7
          }
        ]
      },
      {
        navOne:"",
        id:6,
        navTwo:[
          {
            title:"",
            id:1
          },
          {
            title:"",
            id:2
          },
          {
            title:"",
            id:3
          }
        ]
      },
      {
        navOne:"",
        id:7,
        navTwo:[
          {
            title:"",
            id:1
          },
          {
            title:"",
            id:2
          }
        ]
      },
      {
        navOne:"",
        id:8,
        navTwo:[
          {
            title:"",
            id:1
          },
          {
            title:"",
            id:2
          },
          {
            title:"",
            id:3
          },
          {
            title:"",
            id:4
          },
          {
            title:"",
            id:5
          }
        ]
      }
    ]
    }
  },
   methods: {
     showNav(e){
       console.log(e.currentTarget);
       this.showTag = !this.showTag;
     }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .left{
    width:200px;
    position: fixed;
    background: -sharpf5f5f5;
    top:60px;
    left:0;
    height:calc(100% - 60px);
    z-index: 99;
    overflow-y: auto;
  }
  .left ul > li{
    padding:10px;
    border-bottom:dotted 1px -sharpdedede;
    font-size:15px;
    color:-sharp999;
  }
  .left ul > li i{
    margin-left:5px;
  }
  .left ul > li ul li{
    border-bottom:0;
    font-size:14px;
    color:-sharp333;
  }
</style>

what result do you expect? What is the error message actually seen?

Apr.26,2021

 <div class="left">
            <ul>
                <li></li>
                <li v-for="nav in navList" :key="nav.id" @click="showNav(nav.id)">{{nav.navOne}}
                    <i class="iconfont icon-iconfontjiantou"></i>
                    <ul class="nav-child" v-show="currentTab==nav.id">
                        <li v-for="item in nav.navTwo" :key="item.id">{{item.title}}</li>
                    </ul>
                </li>
            </ul>
</div>
data() {
    return {
          currentTab: '',
          navList: [
                //
          ]
    };
},
methods: {
         showNav(tab) {
            this.currentTab = this.currentTab == tab ? '' : tab; //     
            
          }
}

all your judgments are placed on one variable showTag . Once you click on one, naturally everything changes.


you can customize an instruction, and then expand and fold the current node

.
Menu