Created
November 24, 2020 03:39
-
-
Save ThaddeusJiang/49796a990fd746bd5a73a9cfc4c8e375 to your computer and use it in GitHub Desktop.
Vue Composition API 运行
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vue Composition API 的 setup() 晚于 beforeCreate 钩子(在 Vue 中,“钩子”就是一个生命周期方法)而早于 created 钩子被调用。 | |
这是我们可以分辨 React Hooks 和 Vue Composition API 的首个区别, React hooks 会在组件每次渲染时候运行,而 Vue setup() 只在组件创建时运行一次。 | |
因为前者可以多次运行,所以 render 方法必须遵守 某些规则,其中之一是: | |
> 不要在循环内部、条件语句中或嵌套函数里调用 Hooks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment