Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何看待Vue3的Composition API? #131

Open
GGXXMM opened this issue Apr 7, 2023 · 0 comments
Open

如何看待Vue3的Composition API? #131

GGXXMM opened this issue Apr 7, 2023 · 0 comments
Labels

Comments

@GGXXMM
Copy link
Owner

GGXXMM commented Apr 7, 2023

Composition API 风格

composition API

Options API vs Composition API 区别

Options API Composition-API
不利于复用 方便代码复用,关注点分离
潜在命名冲突,数据源来源不清晰 数据来源清晰
上下文丢失 提供更好的上下文
有限类型支持 更好的TypeScript支持
按API类型支持 按功能/逻辑组织,方便代码复用

总结:Composition API 优点

  • Composition API 根据逻辑相关性组织代码,提高可读性和可维护性
  • 组件间可复用的代码可抽取为hook函数,提高可复用性
  • 更好的 Typescript 支持
  • 灵活度较高
@GGXXMM GGXXMM added the vue label Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant