This article shares the specific code of Vue recursively implementing a custom tree component for your reference. The specific content is as follows 1. In tree/index.vue: <template> <div> <ul> <item :model='data'></item> </ul> </div> </template> <script> import Item from './item' export default { components:{ Item }, data(){ return { data:{ title:"Level 1", children:[ { title:"Level 1-1", children:[ { title:"Level 3 1-1-1", children:[ { Title:"Level 4 1-1-1-1", children:[ { title:"Level 5 1-1-1-1-1" } ] } ] } ] },{ title:'Level 1-2', children:[ { Title:"Level 3 1-2-1" } ] } ] } } } } </script> 2. item.vue component: <template> <li> <div @click="toggle"> {{model.title}} <span v-if="isFolder">[{{open?'-':'+'}}]</span> </div> <ul v-show="open" v-if="isFolder"> <item v-for="(child,index) in model.children" :model='child' :key='index'></item> </ul> </li> </template> <script> export default { name:'Item', props:{ model:{ type:Object, required:true } }, data(){ return { open:false } }, computed:{ isFolder(){ return this.model.children && this.model.children.length>0 } }, methods:{ toggle(){ if (this.isFolder) this.open =!this.open } } } </script> 3. Use in any component: <template> <div class="index"> <Tree></Tree> </div> </template> <script> import Tree from "@/components/tree" components:{ Tree } </script> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of several ways to obtain the PID (TID, LWP) of Linux threads
>>: Detailed explanation of three relationship examples of MySQL foreign keys
In the page, external files such as js, css, etc. ...
This article records the specific steps for downl...
Table of contents How to operate Operation proces...
1. nohup Run the program in a way that ignores th...
In actual work or interviews, we often encounter ...
Configure Git environment in Docker At work, I en...
I have learned some basic selectors of CSS before...
1. Problem introduction Assume a scenario where a...
<br />In the previous article, I introduced ...
Supervisor Introduction Supervisor is a client/se...
This article shares the specific code of Vue to a...
Table of contents Preface Rolling principle accom...
Table of contents 1. Security issues with Docker ...
What is volume? Volume means capacity in English,...
This article uses examples to explain the concept...