mirror of
https://github.com/WGDashboard/WGDashboard-PRW.git
synced 2026-12-01 08:57:40 +00:00
1.7 KiB
1.7 KiB
description, applyTo
| description | applyTo |
|---|---|
| Use when writing or editing Vue, JavaScript or TypeScript in the WGDashboard admin/client apps: Composition API, component size, API layer, stores, locale usage. | src/web/**/*.vue, src/web/**/*.js, src/web/**/*.ts |
Vue style – readability first
<script setup>Composition API only. Pinia stores use the setup syntax ofdefineStore.- Templates contain no logic beyond property access. Everything else becomes a named
computed. - Components ≲ 250 lines. Extract composables (
usePeerSorting,usePeerFilter,usePeerModals). - All HTTP goes through the shared API layer in
src/web/shared(e.g.api.peers.update(...)). No rawfetch/axiosor URL strings in components. async/awaitonly. No callback-style helpers.- Explicit
defineProps(with defaults) anddefineEmits. - Descriptive names; no single-letter variables outside trivial
v-forindexes. - Keep component names and folder structure aligned with
reference/src/static/appandreference/src/static/client, so features can be compared one-to-one. - User-facing text goes through the locale helper with English fallback.
Example
Legacy pattern:
<span>{{ peers.filter(p => p.status === 'running').length }} / {{ peers.length }}</span>
Rewrite:
<script setup>
import { computed } from 'vue'
const props = defineProps({
peers: { type: Array, default: () => [] },
})
const connectedPeerCount = computed(() => {
let count = 0
for (const peer of props.peers) {
if (peer.status === 'running') {
count += 1
}
}
return count
})
</script>
<template>
<span>{{ connectedPeerCount }} / {{ props.peers.length }}</span>
</template>