Apply detailed usage patterns and best practices for Vue SFC in weapp-vite projects. Use when writing or refactoring `.vue` files for mini-programs, choosing `<script setup>` and JSON macro strategy, defining `usingComponents`, handling template directive compatibility (`v-model` / `v-bind` limits), coordinating wevu runtime hooks, or troubleshooting SFC compile/runtime issues.
Resources
2Install
npx skillscat add weapp-vite/weapp-vite/weapp-vite-vue-sfc-best-practices Install via the SkillsCat registry.
SKILL.md
weapp-vite-vue-sfc-best-practices
Overview
Implement Vue SFC in mini-programs with a two-layer mindset: compile-time rules (weapp-vite) and runtime behavior (wevu). Keep SFC structure explicit, avoid web-only assumptions, and optimize for predictable output.
Workflow
- Establish SFC boundaries
- Treat
<template>/<script>/<style>/<json>as separate responsibilities. - Keep mini-program config in
<json>or Script Setup JSON macros. - Avoid script-side ESM component registration for mini-program components.
- Choose script strategy
- Prefer
<script setup lang="ts">for page/component logic. - Import runtime APIs from
wevu(notvue) in business logic. - Keep hook registration synchronous in
setup().
- Configure JSON correctly
- Use one macro family per SFC:
definePageJsonordefineComponentJsonordefineAppJson. - Keep macro calls top-level and single-argument.
- Remember macro output has highest merge priority over
<json>and auto-inferred config.
- Author templates with compatibility constraints
- Use mini-program component/event semantics.
- For
v-model, only use assignable left values (x,x.y,x[i]). - Avoid relying on unsupported patterns (
v-modelmodifiers/arguments,v-bind="object"expansion).
- Coordinate with wevu runtime
- Use
defineComponentmodel for page/component registration. - Use explicit value/event bindings or
bindModelfor complex form components. - Keep page event hooks aligned with page context and trigger conditions.
- Troubleshoot by stage
- Compile-time issues: check macro usage,
usingComponents, template syntax limits. - Runtime issues: check API import source, hook timing, setData/diff expectations.
- IDE/type issues: check Volar plugin and
vueCompilerOptions.libalignment.
Guardrails
- Do not treat mini-program component registration like web Vue component registration.
- Do not register hooks after
awaitinsetup(). - Do not assume web Vue template features are fully available in mini-program compilation.
- Do not mix multiple JSON macro families in one SFC.
Completion Checklist
- SFC config path is clear (
<json>or one JSON macro family). usingComponentsstrategy is deterministic and path-safe.- Template usage avoids unsupported directive forms.
- Runtime API imports come from
wevu. - Hook timing and page/component context are valid.
References
references/macro-config-checklist.mdreferences/template-compat-matrix.mdreferences/troubleshooting-playbook.md