Skip to content

Instantly share code, notes, and snippets.

@ThaddeusJiang
Created November 24, 2020 03:39
Show Gist options
  • Save ThaddeusJiang/49796a990fd746bd5a73a9cfc4c8e375 to your computer and use it in GitHub Desktop.
Save ThaddeusJiang/49796a990fd746bd5a73a9cfc4c8e375 to your computer and use it in GitHub Desktop.
Vue Composition API 运行
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