From de8d3d86a304f0fe0bec816e27c1acbd06e4a96a Mon Sep 17 00:00:00 2001 From: Ben Hong Date: Mon, 6 Jul 2020 12:06:52 -0400 Subject: [PATCH 1/3] docs (#134): add functional components to migration guide --- src/.vuepress/config.js | 2 +- src/guide/migration/functional-components.md | 74 ++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/guide/migration/functional-components.md diff --git a/src/.vuepress/config.js b/src/.vuepress/config.js index 942e852a29..50163185c0 100644 --- a/src/.vuepress/config.js +++ b/src/.vuepress/config.js @@ -75,7 +75,7 @@ const sidebar = { { title: 'Migration to Vue 3', collapsable: true, - children: ['migration'] + children: ['migration', 'migration/functional-components'] }, { title: 'Contribute to the Docs', diff --git a/src/guide/migration/functional-components.md b/src/guide/migration/functional-components.md new file mode 100644 index 0000000000..4588e358c0 --- /dev/null +++ b/src/guide/migration/functional-components.md @@ -0,0 +1,74 @@ +# Functional Components + +## Overview + +In terms of what has changed, at a high level: + +For more context, be sure to read the rest of the guide. + +## Introduction + +In Vue 2, functional components had primary use cases: + +- as a performance optimization, because they initialized much faster than stateful components +- to return multiple root nodes + +However, in Vue 3, the performance of stateful components has improved to the point that the difference is negligible. In addition, stateful components now also include the ability to return multiple root nodes. + +As a result, the only remaining use case for functional components is simple components, such as a component to create a dynamic heading. Otherwise, it is recommended to use stateful components as you normally would. + +## Previous Syntax + +Using the `` component, which is responsible for rendering out the appropriate heading (i.e., `h1`, `h2`, `h3`, etc.), this could have been written as a single-file component in v2 as: + +```js +// Vue 2 Functional Component Example +export default { + functional: true, + props: ['level'], + render(h, { props, data, children }) { + return h(`h${props.level}`, data, children) + } +} +``` + +Or, for those who preferred the `