Save tree state
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue'
|
import { useTreeState } from '~/composables/useTreeState'
|
||||||
|
|
||||||
defineProps({ nodes: Array, depth: { type: Number, default: 0 } })
|
defineProps({ nodes: Array, depth: { type: Number, default: 0 } })
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const collapsed = ref({})
|
const { collapsed } = useTreeState() // ← shared state, not local ref
|
||||||
|
|
||||||
function getTitle(node) {
|
function getTitle(node) {
|
||||||
if (node.title == "index") return "Index"
|
if (node.title === 'index') return 'Index'
|
||||||
return node.title || node._path?.split('/').pop() || 'Home';
|
return node.title || node._path?.split('/').pop() || 'Home'
|
||||||
}
|
}
|
||||||
|
|
||||||
function navigate(path) {
|
function navigate(path) {
|
||||||
|
|||||||
8
template/app/composables/useTreeState.ts
Normal file
8
template/app/composables/useTreeState.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const collapsed = ref<Record<string, boolean>>({})
|
||||||
|
|
||||||
|
export function useTreeState() {
|
||||||
|
function resetTree() {
|
||||||
|
collapsed.value = {}
|
||||||
|
}
|
||||||
|
return { collapsed, resetTree }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user