组件代码
<template v-for="task1 in task0.list">
<div class="db_item">
<a class="db_item_tit" href="javascript:;" @click="activeTab(task1.menuId)"><i class="fa fa-folder"></i>{{task1.name}}({{task1.taskCount}})</a>
<ul>
<task-item :task-item="task1"></task-item>
<div class="clear"></div>
</ul>
</div>
</template>
需要递归的组件taskItem(template要一个标签包起来,比如:div)
<script type="text/javascript">
Vue.component('taskItem', {
template: ''+
'<div>' +
'<div v-if="taskItem.tasks">' +
'<li v-for="task0 in taskItem.tasks"><a href="javascript:;" @click="activeTab(taskItem.menuId, task0.actId)"><i class="fa fa-calendar-check-o"></i>{{task0.actName}}<em>({{task0.taskCount}})</em></a></li>' +
'</div>' +
'<div v-if="taskItem.list">' +
'<task-item v-for="task0 in taskItem.list" :task-item="task0"></task-item>' +
'</div>' +
'</div>' +
'',
data:function() {
return {
}
},
props: {
taskItem:[Object],
},
methods:{
activeTab: function (menuId, actId) {
//...
},
}
});
</script>