0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-06-25 04:04:00 +02:00
gitea/web_src/js/components/ViewFileTree.vue
Kilisei 181db69e0c
Use shallowRef instead of ref in .vue files where possible (#34813)
This PR improves some `.vue` components by using `shallowRef instead of
ref`, which `should improve performance`. It's probably not significant,
but it's an improvement because Vue no longer deep watches the ref
(shallowRef). Also i used `useTemplateRef` instead of `ref`.

---------

Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-06-22 21:37:03 +08:00

39 lines
1.1 KiB
Vue

<script lang="ts" setup>
import ViewFileTreeItem from './ViewFileTreeItem.vue';
import {onMounted, useTemplateRef} from 'vue';
import {createViewFileTreeStore} from './ViewFileTreeStore.ts';
const elRoot = useTemplateRef('elRoot');
const props = defineProps({
repoLink: {type: String, required: true},
treePath: {type: String, required: true},
currentRefNameSubURL: {type: String, required: true},
});
const store = createViewFileTreeStore(props);
onMounted(async () => {
store.rootFiles = await store.loadChildren('', props.treePath);
elRoot.value.closest('.is-loading')?.classList?.remove('is-loading');
window.addEventListener('popstate', (e) => {
store.selectedItem = e.state?.treePath || '';
if (e.state?.url) store.loadViewContent(e.state.url);
});
});
</script>
<template>
<div class="view-file-tree-items" ref="elRoot">
<ViewFileTreeItem v-for="item in store.rootFiles" :key="item.name" :item="item" :store="store"/>
</div>
</template>
<style scoped>
.view-file-tree-items {
display: flex;
flex-direction: column;
gap: 1px;
margin-right: .5rem;
}
</style>