Vue 3 中如何使用 Composition API 实现组件间的状态共享?
{{ state.count }}
```
**Parsing:**
- Vue 3's Composition API allows encapsulating logic into functions (i.e., composable functions), which can be reused across multiple components.
- By using `reactive` to create reactive state and `readonly` to prevent direct external modification, the state is only updated through defined methods (similar to Vuex's mutations).
- This approach does not require introducing Vuex or Pinia (though Pinia is the official recommended state management library for larger applications). It is suitable for simple state sharing in smaller projects.
- For more complex state management (e.g., time travel, plugin systems), Pinia is recommended.
**Note:** This method leverages the singleton nature of JavaScript modules—i.e., importing the same module multiple times results in shared state.