组件递归实现简单目录树之组件源码 {{obj.name}} {{open?'-':'+'}} 组件递归实现简单目录树之data格式 var data = { name: '树', children: [{ name: '1-1.千月君' }, { name: '1-2.喜欢 Vue.js' }, { name: '1-3.目录
组件递归实现简单目录树之data格式{{obj.name}} {{open?'-':'+'}}
var data = { name: '树', children: [{ name: '1-1.千月君' }, { name: '1-2.喜欢 Vue.js' }, { name: '1-3.目录', children: [{ name: '1-3-1.子目录1', children: [{ name: '1-3-1-1.子目录1的子节点1' }, { name: '1-3-1-2.子目录1的子节点2' }] }, { name: '1-3-2.子目录2' }, { name: '1-3-3.子目录2的子节点1' }] } ] }组件递归实现简单目录树之Vue实例
Vue.component('li-item', { template: '#li-item', props: { obj: Object }, data: function() { return { open: false } }, computed: { isFold: function() { return this.obj.children && this.obj.children.length } }, methods: { toggle: function() { if(this.isFolder) { this.open = !this.open; } } } })效果展示.png