wevu-best-practices
Original:🇺🇸 English
Translated
Apply Vue-3-style runtime best practices for wevu in mini-programs. Use when implementing pages/components/stores with wevu, defining lifecycle hooks, handling setData diff behavior, designing props/emit and bindModel flows, integrating with weapp-vite SFC JSON macros, or troubleshooting compatibility differences versus Vue 3.
2installs
Sourcesonofmagic/skills
Added on
NPX Install
npx skill4agent add sonofmagic/skills wevu-best-practicesTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →wevu-best-practices
Overview
Write mini-program business logic with Vue-style ergonomics while respecting wevu runtime constraints. Keep hooks, state updates, and component contracts explicit.
Workflow
- Set runtime conventions first
- Import runtime APIs only from .
wevu - Use as the registration model for both pages and components.
defineComponent - Keep as a function when using options-style state.
data
- Use correct component/page boundaries
- Define mini-program config via Script Setup JSON macros first.
- For App/Page/Component SFC, prefer /
defineAppJson/definePageJsonoverdefineComponentJsonblocks.<json> - Declare through JSON config, not script-side ESM component registration.
usingComponents - Keep page hooks only in page contexts.
- Keep reactive updates predictable
- Use for state and derive template data from them.
ref/reactive/computed - Register lifecycle hooks synchronously inside .
setup() - Use explicit bindings for forms/events when semantics are complex.
- Design events and two-way binding intentionally
- Use with mini-program event semantics.
ctx.emit(event, detail, options) - For reusable field bindings, prefer /
bindModelwith explicit event and parser.useBindModel - Avoid assuming full Vue web feature parity in mini-program templates.
v-model
- Structure stores for maintainability
- Prefer Setup Store for simple domains and strong inference.
- Use when destructuring state/getters.
storeToRefs - Add only when global plugin/persistence hooks are needed.
createStore()
- Handle compatibility and testing explicitly
- Do not use DOM/browser-only APIs in runtime logic.
- For Node/Vitest tests, stub /
Componentwhen testing runtime bridges.wx - Treat lifecycle and provide/inject differences as platform constraints, not bugs.
Guardrails
- Avoid hook registration after in
await.setup() - Avoid direct state destructuring without for stores.
storeToRefs - Avoid relying on undocumented Vue web-only behavior in templates or lifecycle timing.
Completion Checklist
- API imports come from , not
wevuruntime in business code.vue - Page/component JSON config strategy is consistent.
- Hook registration timing is synchronous and predictable.
- Store usage follows singleton + conventions.
storeToRefs - Template bindings match mini-program-supported semantics.
References
references/component-patterns.mdreferences/store-patterns.mdreferences/troubleshooting-checks.md