-
Notifications
You must be signed in to change notification settings - Fork 87
Guide > Components In-Depth > Slots の翻訳を追従 #293
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
Changes from all commits
9c1d767
c06c5b0
9f826e9
dee3834
3918ee2
cde593c
90eb124
f091edc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ Vue には [Web Components spec draft](https://github.com/w3c/webcomponents/blob | |
<todo-button> | ||
<!-- コンポーネントを使ってアイコンを追加 --> | ||
<font-awesome-icon name="plus"></font-awesome-icon> | ||
Your Profile | ||
Add todo | ||
</todo-button> | ||
``` | ||
|
||
|
@@ -100,7 +100,6 @@ Vue には [Web Components spec draft](https://github.com/w3c/webcomponents/blob | |
|
||
> 親のテンプレート内の全てのものは親のスコープでコンパイルされ、子のテンプレート内の全てのものは子のスコープでコンパイルされる。 | ||
|
||
|
||
## フォールバックコンテンツ | ||
|
||
スロットに対して、コンテンツがない場合にだけ描画されるフォールバック (つまり、デフォルトの) コンテンツを指定すると便利な場合があります。例えば、`<submit-button>` コンポーネントにおいて: | ||
|
@@ -222,7 +221,8 @@ Vue には [Web Components spec draft](https://github.com/w3c/webcomponents/blob | |
</footer> | ||
</div> | ||
``` | ||
**`v-slot` は([一つの例外](#デフォルトスロットしかない場合の省略記法) を除き) `<template>` にしか指定できないことに注意してください。 | ||
|
||
**`v-slot` は([一つの例外](#デフォルトスロットしかない場合の省略記法) を除き) `<template>` にしか指定できないことに注意してください。 | ||
|
||
## スコープ付きスロット | ||
|
||
|
@@ -247,8 +247,7 @@ app.component('todo-list', { | |
}) | ||
``` | ||
|
||
親コンポーネントでこれをカスタマイズするために、スロットに交換してもよいでしょう: | ||
|
||
親コンポーネントでこれをカスタマイズするために、<span v-pre>`{{ item }}`</span> を `<slot>` に置き換えたい場合があります: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 原文ですが、
となっていて、 https://v3.vuejs.org/guide/component-slots.html#scoped-slots There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここで問題になっていた下図の現象、日本語訳でも起きちゃうんですよね。 原文はこちらです。 https://github.com/vuejs/docs-next/blob/master/src/guide/component-slots.md#L250 VuePress の hack のようなものなのですが、そのまま取り込もうと思います。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. なるほど... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 原文と同じく、取り込みましょう! |
||
|
||
```html | ||
<todo-list> | ||
|
@@ -259,23 +258,33 @@ app.component('todo-list', { | |
|
||
しかし、これは動作しません。というのも、 `item` にアクセスすることができるのは `<todo-list>` コンポーネントだけですが、ここで指定しているコンテンツは親コンポーネントで描画されるからです。 | ||
|
||
親コンポーネント内でスロットコンテンツとして `item` を使えるようにするためには、これを `<slot>` 要素の属性としてバインドします: | ||
親コンポーネント内でスロットコンテンツとして `item` を使えるようにするためには、これを `<slot>` 要素の属性として束縛します: | ||
|
||
```html | ||
<ul> | ||
<li v-for="( item, index ) in items"> | ||
<slot v-bind:item="item"></slot> | ||
<slot :item="item"></slot> | ||
</li> | ||
</ul> | ||
``` | ||
|
||
`<slot>` 要素にバインドされた属性は、 **スロットプロパティ** と呼ばれます。これで、親スコープ内で `v-slot` に値を指定して、渡されたスロットプロパティの名前を定義できます: | ||
必要な数の属性を `slot` に束縛できます: | ||
|
||
```html | ||
<ul> | ||
<li v-for="( item, index ) in items"> | ||
<slot :item="item" :index="index" :another-attribute="anotherAttribute"></slot> | ||
</li> | ||
</ul> | ||
``` | ||
|
||
`<slot>` 要素に束縛された属性は、 **スロットプロパティ** と呼ばれます。これで、親スコープ内で `v-slot` に値を指定して、渡されたスロットプロパティの名前を定義できます: | ||
|
||
```html | ||
<todo-list> | ||
<template v-slot:default="slotProps"> | ||
<i class="fas fa-check"></i> | ||
<span class="green">{{ slotProps.item }}<span> | ||
<span class="green">{{ slotProps.item }}</span> | ||
</template> | ||
</todo-list> | ||
``` | ||
|
@@ -291,7 +300,7 @@ app.component('todo-list', { | |
```html | ||
<todo-list v-slot:default="slotProps"> | ||
<i class="fas fa-check"></i> | ||
<span class="green">{{ slotProps.item }}<span> | ||
<span class="green">{{ slotProps.item }}</span> | ||
</todo-list> | ||
``` | ||
|
||
|
@@ -300,7 +309,7 @@ app.component('todo-list', { | |
```html | ||
<todo-list v-slot="slotProps"> | ||
<i class="fas fa-check"></i> | ||
<span class="green">{{ slotProps.item }}<span> | ||
<span class="green">{{ slotProps.item }}</span> | ||
</todo-list> | ||
``` | ||
|
||
|
@@ -309,10 +318,9 @@ app.component('todo-list', { | |
```html | ||
<!-- 不正。警告が出ます --> | ||
<todo-list v-slot="slotProps"> | ||
<todo-list v-slot:default="slotProps"> | ||
<i class="fas fa-check"></i> | ||
<span class="green">{{ slotProps.item }}<span> | ||
</todo-list> | ||
<i class="fas fa-check"></i> | ||
<span class="green">{{ slotProps.item }}</span> | ||
|
||
<template v-slot:other="otherSlotProps"> | ||
slotProps is NOT available here | ||
</template> | ||
|
@@ -325,13 +333,13 @@ app.component('todo-list', { | |
<todo-list> | ||
<template v-slot:default="slotProps"> | ||
<i class="fas fa-check"></i> | ||
<span class="green">{{ slotProps.item }}<span> | ||
<span class="green">{{ slotProps.item }}</span> | ||
</template> | ||
|
||
<template v-slot:other="otherSlotProps"> | ||
... | ||
</template> | ||
</current-user> | ||
</todo-list> | ||
``` | ||
|
||
### スロットプロパティの分割代入 | ||
|
@@ -358,7 +366,7 @@ function (slotProps) { | |
```html | ||
<todo-list v-slot="{ item: todo }"> | ||
<i class="fas fa-check"></i> | ||
<span class="green">{{ todo }}<span> | ||
<span class="green">{{ todo }}</span> | ||
</todo-list> | ||
``` | ||
|
||
|
@@ -387,7 +395,6 @@ function (slotProps) { | |
|
||
`v-on` や `v-bind` と同様に `v-slot` にも省略記法があり、引数の前のすべての部分 (`v-slot:`) を特別な記号 `#` で置き換えます。例えば、`v-slot:header` は `#header` に書き換えることができます: | ||
|
||
|
||
```html | ||
<base-layout> | ||
<template #header> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「デフォルトスロット」の「デ」に差分があってページ内リンクが動作してなかったため修正しました。