Skip to content

Commit 007d213

Browse files
authored
Merge pull request #155 from kawamataryo/translate-custome-elements-interop
Translate: Migration Guide > Migration > Custom Elements Interop
2 parents 8351b58 + 025d359 commit 007d213

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

src/guide/migration/custom-elements-interop.md

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@ badges:
33
- breaking
44
---
55

6-
# Custom Elements Interop changes <MigrationBadges :badges="$frontmatter.badges" />
6+
# カスタム要素の相互運用性 <MigrationBadges :badges="$frontmatter.badges" />
77

8-
# Overview
8+
## 概要
99

10-
- **BREAKING:** Custom elements whitelisting is now performed during template compilation, and should be configured via compiler options instead of runtime config.
11-
- **BREAKING:** Special `is` prop usage is restricted to the reserved `<component>` tag only.
12-
- **NEW:** There is new `v-is` directive to support 2.x use cases where `is` was used on native elements to work around native HTML parsing restrictions.
10+
- **BREAKING:** カスタム要素のホワイトリスト化はテンプレートのコンパイル中に実行されるようになりました。そのためランタイム設定ではなくコンパイラオプションで設定する必要があります。
11+
- **BREAKING:** 特別な `is` プロパティの使用は予約済みの `<component>` タグのみに制限されます。
12+
- **NEW:** 新しい `v-is` ディレクティブが追加され、ネイティブ HTML のパース制限を回避するためにネイティブ要素で `is` が使用されていた 2.x のユースケースをサポートするようになりました。
1313

14-
## Autonomous Custom Elements
14+
## 自主的なカスタム要素
1515

16-
If we want to add a custom element defined outside of Vue (e.g. using the Web Components API), we need to 'instruct' Vue to treat it as a custom element. Let's use the following template as an example.
16+
Vue の外部で定義されたカスタム要素を追加したい場合(例えば Web Components API の使用)、Vue にカスタム要素として扱うように「指示」する必要があります。以下のテンプレートを例にしてみましょう。
1717

1818
```html
1919
<plastic-button></plastic-button>
2020
```
2121

22-
### 2.x Syntax
22+
### 2.x での構文
2323

24-
In Vue 2.x, whitelisting tags as custom elements was done via `Vue.config.ignoredElements`:
24+
Vue 2.x では、カスタム要素としてのタグのホワイトリスト化は `Vue.config.ignoredElements` で行われていました。
2525

2626
```js
27-
// This will make Vue ignore custom element defined outside of Vue
28-
// (e.g., using the Web Components APIs)
27+
// 以下で Vue Vue の外部で定義されたカスタム要素を無視するようになります
28+
// (例: Components APIの使用)
2929

3030
Vue.config.ignoredElements = ['plastic-button']
3131
```
3232

33-
### 3.x Syntax
33+
### 3.x での構文
3434

35-
**In Vue 3.0, this check is performed during template compilation.** To instruct the compiler to treat `<plastic-button>` as a custom element:
35+
**Vue 3.0 では、このチェックはテンプレートのコンパイル時に実行されます。** コンパイラに `<plastic-button>` をカスタム要素として扱うように指示するには、以下のようにします。
3636

37-
- If using a build step: pass the `isCustomElement` option to the Vue template compiler. If using `vue-loader`, this should be passed via `vue-loader`'s `compilerOptions` option:
37+
- ビルドステップを使用する場合: Vue テンプレートコンパイラに `isCustomElement` オプションを設定します。`vue-loader` を使用している場合は、`vue-loader``compilerOptions` オプションを介して設定する必要があります。
3838

3939
```js
40-
// in webpack config
40+
// webpackの設定
4141
rules: [
4242
{
4343
test: /\.vue$/,
@@ -52,68 +52,68 @@ Vue.config.ignoredElements = ['plastic-button']
5252
]
5353
```
5454

55-
- If using on-the-fly template compilation, pass it via `app.config.isCustomElement`:
55+
- 直接テンプレートをコンパイルする場合は、`app.config.isCustomElement`で設定します。
5656

5757
```js
5858
const app = Vue.createApp({})
5959
app.config.isCustomElement = tag => tag === 'plastic-button'
6060
```
6161

62-
It's important to note the runtime config only affects runtime template compilation - it won't affect pre-compiled templates.
62+
ランタイム設定はランタイムテンプレートのコンパイルにしか影響しないことに注意してください - コンパイル済みのテンプレートには影響しません。
6363

64-
## Customized Built-in Elements
64+
## カスタマイズされたビルトイン要素
6565

66-
The Custom Elements specification provides a way to use custom elements as [Customized Built-in Element](https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-customized-builtin-example) by adding the `is` attribute to a built-in element:
66+
カスタム要素の仕様では、ビルトイン要素に`is`属性を追加するとこで、カスタム要素を[カスタマイズされたビルトイン要素](https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-customized-builtin-example)として利用する方法を提供しています。
6767

6868
```html
6969
<button is="plastic-button">Click Me!</button>
7070
```
7171

72-
Vue's usage of the `is` special prop was simulating what the native attribute does before it was made universally available in browsers. However, in 2.x it was interpreted as rendering a Vue component with the name `plastic-button`. This blocks the native usage of Customized Built-in Element mentioned above.
72+
Vue では、ブラウザで普遍的に利用できるようになる前のネイティブ属性の動作をシミュレートするために、特別なプロパティ `is` を使用していました。しかし、2.x では、`plastic-button`という名前の Vue コンポーネントをレンダリングしていると解釈されていました。これにより、上記のカスタマイズされたビルトイン要素のネイティブな使用がブロックされます。
7373

74-
In 3.0, we are limiting Vue's special treatment of the `is` prop to the `<component>` tag only.
74+
3.0では、Vue`is` プロパティの特別な扱いを `<component>` タグのみに制限しています。
7575

76-
- When used on the reserved `<component>` tag, it will behave exactly the same as in 2.x;
77-
- When used on normal components, it will behave like a normal prop:
76+
- 予約済みの `<component>` タグで使用された場合、2.x と全く同じ動作をします。
77+
- 通常のコンポーネントに使用すると、通常のプロパティのように動作します。
7878

7979
```html
8080
<foo is="bar" />
8181
```
8282

83-
- 2.x behavior: renders the `bar` component.
84-
- 3.x behavior: renders the `foo` component and passing the `is` prop.
83+
- 2.x の動作: `bar` コンポーネントをレンダリングします。
84+
- 3.x の動作: `foo` コンポーネントをレンダリングし、`is` プロパティを渡します。
8585

86-
- When used on plain elements, it will be passed to the `createElement` call as the `is` option, and also rendered as a native attribute. This supports the usage of customized built-in elements.
86+
- 通常の要素で使用される場合、`is` オプションとして `createElement` の呼び出しに渡され、ネイティブ属性としてもレンダリングされます。これはカスタマイズされたビルトイン要素の使用をサポートします。
8787

8888
```html
8989
<button is="plastic-button">Click Me!</button>
9090
```
9191

92-
- 2.x behavior: renders the `plastic-button` component.
93-
- 3.x behavior: renders a native button by calling
92+
- 2.x の動作: `plastic-button` コンポーネントをレンダリングします。
93+
- 3.x の動作: ネイティブなボタンをレンダリングします。
9494

9595
```js
9696
document.createElement('button', { is: 'plastic-button' })
9797
```
9898

99-
## `v-is` for In-DOM Template Parsing Workarounds
99+
## `v-is` In-DOM テンプレートパースのための回避策
100100

101-
> Note: this section only affects cases where Vue templates are directly written in the page's HTML.
102-
> When using in-DOM templates, the template is subject to native HTML parsing rules. Some HTML elements, such as `<ul>`, `<ol>`, `<table>` and `<select>` have restrictions on what elements can appear inside them, and some elements such as `<li>`, `<tr>`, and `<option>` can only appear inside certain other elements.
101+
> : このセクションは、Vue テンプレートがページの HTML に直接記述されている場合にのみ影響します。
102+
> in-DOM テンプレートを使用している場合、テンプレートはネイティブ HTML パースルールに従います。HTML 要素の中には、`<ul>`, `<ol>`, `<table>`, `<select>` のように、その中に表示できる要素に制限があり、また、`<li>`, `<tr>`, `<option>` のように、特定の他の要素の中にしか表示できない要素もあります。
103103

104-
### 2.x Syntax
104+
### 2.x での構文
105105

106-
In Vue 2 we recommended working around with these restrictions by using the `is` prop on a native tag:
106+
Vue 2 では、ネイティブタグに `is` プロパティを使用してこれらの制限を回避することを推奨しています。
107107

108108
```html
109109
<table>
110110
<tr is="blog-post-row"></tr>
111111
</table>
112112
```
113113

114-
### 3.x Syntax
114+
### 3.x での構文
115115

116-
With the behavior change of `is`, we introduce a new directive `v-is` for working around these cases:
116+
`is` の動作変更に伴い、これらのケースを回避するための新しいディレクティブ `v-is` を導入されました。
117117

118118
```html
119119
<table>
@@ -122,20 +122,20 @@ With the behavior change of `is`, we introduce a new directive `v-is` for workin
122122
```
123123

124124
:::warning
125-
`v-is` functions like a dynamic 2.x `:is` binding - so to render a component by its registered name, its value should be a JavaScript string literal:
125+
`v-is` は動的な 2.x `:is` バインディングのように機能します - コンポーネントを登録された名前でレンダリングするには、その値は JavaScript の文字列リテラルでなければなりません。
126126

127127
```html
128-
<!-- Incorrect, nothing will be rendered -->
128+
<!-- 間違いです。これだと何もレンダリングされません -->
129129
<tr v-is="blog-post-row"></tr>
130130
131-
<!-- Correct -->
131+
<!-- 正解 -->
132132
<tr v-is="'blog-post-row'"></tr>
133133
```
134134

135135
:::
136136

137-
## Migration Strategy
137+
## 移行の戦略
138138

139-
- Replace `config.ignoredElements` with either `vue-loader`'s `compilerOptions` (with the build step) or `app.config.isCustomElement` (with on-the-fly template compilation)
139+
- `config.ignorededElements``vue-loader``compilerOptions` (ビルドステップ) または `app.config.isCustomElement` (直接テンプレートコンパイル) のいずれかで置き換えます。
140140

141-
- Change all non-`<component>` tags with `is` usage to `<component is="...">` (for SFC templates) or `v-is` (for in-DOM templates).
141+
- `<component>`以外のタグで `is` を使用しているものはすべて `<component is="...">` (SFC テンプレートの場合) または `v-is` (in-DOM テンプレートの場合) に変更します。

0 commit comments

Comments
 (0)