From a500de453bd9485415281da00ee358a2fb92d3ea Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Thu, 29 Apr 2021 17:31:06 +0900 Subject: [PATCH 01/17] docs: Add migration guide for h rendering registered component https://github.com/vuejs/docs-next/commit/706a8cdeb0a6ff5aea4b8d6d7ed1996c785274fd#diff-0b635f32793fe88d869035c17f5143d6a7011183741021e19963a52beb70927a --- src/guide/render-function.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guide/render-function.md b/src/guide/render-function.md index 4b676daf..ee810aa2 100644 --- a/src/guide/render-function.md +++ b/src/guide/render-function.md @@ -400,7 +400,7 @@ render() { ```js Vue.h( - 'anchored-heading', + Vue.resolveComponent('anchored-heading'), { level: 1 }, From 7ce9ffb4f606a888175b8ae8880020302aa72e7e Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Thu, 29 Apr 2021 17:32:14 +0900 Subject: [PATCH 02/17] correct misleading content about render function https://github.com/vuejs/docs-next/commit/9ae70db2aa1145b27bdd301729f79c6c1bb7ba1c#diff-0b635f32793fe88d869035c17f5143d6a7011183741021e19963a52beb70927a --- src/guide/render-function.md | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/guide/render-function.md b/src/guide/render-function.md index ee810aa2..d9dc6a03 100644 --- a/src/guide/render-function.md +++ b/src/guide/render-function.md @@ -301,26 +301,16 @@ render() { #### イベント修飾子 -`.passive` 、 `.capture` 、 `.once` イベント修飾子については、Vue はハンドラーのオブジェクトシンタックスを提供しています: +For the `.passive`, `.capture`, and `.once` event modifiers, they can be concatenated after event name using camel case. 例えば: ```javascript render() { return Vue.h('input', { - onClick: { - handler: this.doThisInCapturingMode, - capture: true - }, - onKeyup: { - handler: this.doThisOnce, - once: true - }, - onMouseover: { - handler: this.doThisOnceInCapturingMode, - once: true, - capture: true - }, + onClickCapture: this.doThisInCapturingMode, + onKeyupOnce: this.doThisOnce, + onMouseoverOnceCapture: this.doThisOnceInCapturingMode, }) } ``` From 0d60f4ed7e48ded755571813a2639dfe34b69880 Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Thu, 29 Apr 2021 17:33:42 +0900 Subject: [PATCH 03/17] fix: correct two examples of using h with components and slots https://github.com/vuejs/docs-next/commit/dbeed5b73a88d8c8852a52626e9e431fe47ea991#diff-0b635f32793fe88d869035c17f5143d6a7011183741021e19963a52beb70927a --- src/guide/render-function.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/guide/render-function.md b/src/guide/render-function.md index d9dc6a03..35fc5295 100644 --- a/src/guide/render-function.md +++ b/src/guide/render-function.md @@ -375,11 +375,15 @@ render 関数で子コンポーネントにスロットを渡す方法: render() { // `
{{ props.text }}
` return Vue.h('div', [ - Vue.h('child', {}, { + Vue.h( + Vue.resolveComponent('child'), + {}, // { name: props => VNode | Array } の形で // 子供のオブジェクトを `slots` として渡す - default: (props) => Vue.h('span', props.text) - }) + { + default: (props) => Vue.h('span', props.text) + } + ) ]) } ``` @@ -394,7 +398,9 @@ Vue.h( { level: 1 }, - [Vue.h('span', 'Hello'), ' world!'] + { + default: () => [Vue.h('span', 'Hello'), ' world!'] + } ) ``` From 74996251c1c76df028abfe2ea376ecf5cb303399 Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Thu, 29 Apr 2021 17:34:23 +0900 Subject: [PATCH 04/17] fix: add an emits option to examples that emit events https://github.com/vuejs/docs-next/commit/e554cd6f15fb201d8dc9e03e0f07e4a80e776f19#diff-0b635f32793fe88d869035c17f5143d6a7011183741021e19963a52beb70927a --- src/guide/render-function.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/guide/render-function.md b/src/guide/render-function.md index 35fc5295..e95b52ca 100644 --- a/src/guide/render-function.md +++ b/src/guide/render-function.md @@ -279,6 +279,7 @@ render() { ```js props: ['modelValue'], +emits: ['update:modelValue'], render() { return Vue.h(SomeComponent, { modelValue: this.modelValue, From 89dd25922441b4a6d70c1d320f2d1ad2cd0d64a7 Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Thu, 29 Apr 2021 17:35:25 +0900 Subject: [PATCH 05/17] Update render-function.md https://github.com/vuejs/docs-next/commit/2915212b7e5d26ef797230a01aaee87b82bc0610#diff-0b635f32793fe88d869035c17f5143d6a7011183741021e19963a52beb70927a --- src/guide/render-function.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guide/render-function.md b/src/guide/render-function.md index e95b52ca..e297e72e 100644 --- a/src/guide/render-function.md +++ b/src/guide/render-function.md @@ -238,7 +238,7 @@ render() { ```js render() { return Vue.h('div', - Array.apply(null, { length: 20 }).map(() => { + Array.from({ length: 20 }).map(() => { return Vue.h('p', 'hi') }) ) From 1184c931de2413e9922d8ff5582135aa66dfafaa Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Thu, 29 Apr 2021 17:44:16 +0900 Subject: [PATCH 06/17] Expand the page on render functions, especially their use of slots https://github.com/vuejs/docs-next/commit/ac5bec37431e43f91c61db6089f4b48058d7961a#diff-0b635f32793fe88d869035c17f5143d6a7011183741021e19963a52beb70927a --- src/guide/render-function.md | 150 ++++++++++++++++++++++++++++++++--- 1 file changed, 141 insertions(+), 9 deletions(-) diff --git a/src/guide/render-function.md b/src/guide/render-function.md index e297e72e..d1832e93 100644 --- a/src/guide/render-function.md +++ b/src/guide/render-function.md @@ -62,9 +62,7 @@ const app = Vue.createApp({}) app.component('anchored-heading', { render() { - const { h } = Vue - - return h( + return Vue.h( 'h' + this.level, // タグ名 {}, // props/属性 this.$slots.default() // 子供の配列 @@ -169,6 +167,8 @@ h( ) ``` +If there are no props then the children can usually be passed as the second argument. In cases where that would be ambiguous, `null` can be passed as the second argument to keep the children as the third argument. + ## 完全な例 この知識によって、書き始めたコンポーネントを今では完成させることができます: @@ -245,6 +245,47 @@ render() { } ``` +## Creating Component VNodes + +To create a VNode for a component, the first argument passed to `h` should be the component itself: + +```js +render() { + return Vue.h(ButtonCounter) +} +``` + +If we need to resolve a component by name then we can call `resolveComponent`: + +```js +render() { + const ButtonCounter = Vue.resolveComponent('ButtonCounter') + return Vue.h(ButtonCounter) +} +``` + +`resolveComponent` is the same function that templates use internally to resolve components by name. + +A `render` function will normally only need to use `resolveComponent` for components that are [registered globally](/guide/component-registration.html#global-registration). [Local component registration](/guide/component-registration.html#local-registration) can usually be skipped altogether. Consider the following example: + +```js +// We can simplify this +components: { + ButtonCounter +}, +render() { + return Vue.h(Vue.resolveComponent('ButtonCounter')) +} +``` + +Rather than registering a component by name and then looking it up we can use it directly instead: + +```js +render() { + return Vue.h(ButtonCounter) +} +``` + ## テンプレートの機能をプレーンな JavaScript で置き換える ### `v-if` と `v-for` @@ -273,6 +314,8 @@ render() { } ``` +In a template it can be useful to use a `