vue 遞迴 無限極
阿新 • • 發佈:2020-08-12
demo(父元件向子元件傳值,將子元件註冊進父元件中,父元件擁有子元件的功能)
- index.js
-
import Parent from '@/components/Parent' Vue.use(Router) export default new Router({ mode: 'history', routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld }, { path: '/Parent', name: 'Parent', component: Parent }, ] })
-
- list.vue
-
<template> <div> <div class="list-item" v-for="(item, index) in list" :key="index"> <div class="item-name"> <span>{{item.name}}</span> </div> <div v-if="item.children" class="children-item"> <list :list="item.children"></list> </div> </div> </div> </template> <script> export
-
- Parent.vue
-
<template> <div class="list-detail"> <list :list="list"></list> </div> </template> <script> //
-
- 效果