forked from unjs/unstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileTreeNode.vue
53 lines (50 loc) · 997 Bytes
/
FileTreeNode.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<template>
<li class="filetree-node">
<div @click="onOpen">
{{ item.name }} <span v-if="isDirectory">[{{ isOpen ? '-' : '+' }}]</span>
</div>
<ul v-if="isOpen && item.children.length">
<file-tree-node
v-for="child of item.children"
:key="child.name"
:item="child"
@open="path => $emit('open', path)"
/>
</ul>
</li>
</template>
<script>
import { defineComponent, ref } from 'vue'
export default defineComponent({
props: {
item: {
type: Object,
required: true
}
},
setup (props) {
return {
isOpen: ref((props.item.path || '').split(':').length < 3)
}
},
computed: {
isDirectory () {
return this.item.children.length
}
},
methods: {
onOpen () {
if (this.isDirectory) {
this.isOpen = !this.isOpen
} else {
this.$emit('open', this.item.path)
}
}
}
})
</script>
<style scoped>
.filetree-node {
cursor: pointer;
}
</style>