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 新特性 #15

Open
HelenHai opened this issue Sep 13, 2021 · 0 comments
Open

Vue3 新特性 #15

HelenHai opened this issue Sep 13, 2021 · 0 comments

Comments

@HelenHai
Copy link
Owner

特性1: Composition API

相对于 Vue2.x 中 Options API 的组织方式,Composition API 按照功能去区分代码模块,时一个功能所定义的所有API 放在一起,从而达到 高内聚、低耦合 的目的
image

Options API

首先,所谓 Options API 时在Vue2.x中定义的处理页面逻辑的代码框架

// *.vue 文件
export default {
  data() {
    return{}
  },
  methods: {},
  computed: {},
  watch: {},
}

这种组织形式的特点可以总结为:按照其分工来组织代码,在结构上非常清晰。但是缺点也比较明显,当页面的复杂度足够高时,data 和 methods中的变量和方法过多,使代码维护成本增加。(See Figure.1)

Composition API

按照功能模块来划分代码结构,使代码结构变的更加清晰,数据来源更加清晰。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant