8000 Guide > Reusability & Composition > Render functions の翻訳を追従 by naokie · Pull Request #308 · vuejs-jp/ja.vuejs.org · GitHub
[go: up one dir, main page]

Skip to content

Guide > Reusability & Composition > Render functions の翻訳を追従 #308

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

Merged
merged 17 commits into from
May 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add a section about functional components
  • Loading branch information
naokie committed Apr 29, 2021
commit 508c5aeae7375593473b7d4373126264b237f633
31 changes: 28 additions & 3 deletions src/guide/render-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ return h('h1', {}, this.blogTitle)
```js
// @returns {VNode}
h(
// {String | Object | Function } tag
// HTMLタグ名、コンポーネントまたは非同期コンポーネント
// nullを返す関数を使用した場合、コメントがレンダリングされます
// {String | Object | Function} tag
// HTMLタグ名、コンポーネント、非同期コンポーネント、
// または関数型コンポーネント
//
// 必須
'div',
Expand Down Expand Up @@ -609,6 +609,31 @@ app.mount('#demo')

JSX がどのように JavaScript に変換されるのか、より詳細な情報は、 [使用方法](https://github.com/vuejs/jsx-next#installation) を見てください。

## Functional Components

Functional components are an alternative form of component that don't have any state of their own. They are rendered without creating a component instance, bypassing the usual component lifecycle.

To create a functional component we use a plain function, rather than an options object. The function is effectively the `render` function for the component. As there is no `this` reference for a functional component, Vue will pass in the `props` as the first argument:

```js
const FunctionalComponent = (props, context) => {
// ...
}
```

The second argument, `context`, contains three properties: `attrs`, `emit`, and `slots`. These are equivalent to the instance properties [`$attrs`](/api/instance-properties.html#attrs), [`$emit`](/api/instance-methods.html#emit), and [`$slots`](/api/instance-properties.html#slots) respectively.

Most of the usual configuration options for components are not available for functional components. However, it is possible to define [`props`](/api/options-data.html#props) and [`emits`](/api/options-data.html#emits) by adding them as properties:

```js
FunctionalComponent.props = ['value']
FunctionalComponent.emits = ['click']
```

If the `props` option is not specified, then the `props` object passed to the function will contain all attributes, the same as `attrs`. The prop names will not be normalized to camelCase unless the `props` option is specified.

Functional components can be registered and consumed just like normal components. If you pass a function as the first argument to `h`, it will be treated as a functional component.

## テンプレートのコンパイル

あなたは Vue のテンプレートが実際に render 関数にコンパイルされることに興味があるかもしれません。これは通常知っておく必要のない実装の詳細ですが、もし特定のテンプレートの機能がどのようにコンパイルされるか知りたいのなら、これが面白いかもしれません。これは、 `Vue.compile` を使用してテンプレートの文字列をライブコンパイルする小さなデモです:
Expand Down
0