Overview of Mpx Composition API
masterThe Composition API in Mpx is inspired by Vue 3 and is designed to improve logic reuse, code organization, and TypeScript type inference. Unlike React Hooks, the setup function in Mpx executes only once during initialization, which simplifies the mental model for developers.
Key Advantages:
- Logic Reuse: Uses functions to wrap reusable logic, avoiding the pitfalls of traditional mixins.
- Flexible Organization: Allows developers to group functional code together, making complex components more cohesive.
- Type Safety: Built on local variables and functions, making it inherently friendly to TypeScript without the overhead of
this-based type inference.
Note on Implementation: Mpx does not aim for 100% parity with Vue 3's Composition API. Instead, it adapts Vue 3's design philosophy to fit the specific development patterns of Mpx and mini-programs. Some API implementations may differ from Vue 3.