Skip to content

Commit e67072f

Browse files
authored
Merge pull request #148 from Shohei-Japan/guide-migration-v-bind-merge-behavior
Migration Guide > v-bind Merge Behavior の翻訳
2 parents 7575a61 + 2e4215e commit e67072f

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ const sidebar = {
128128
'migration/render-function-api',
129129
'migration/slots-unification',
130130
'migration/transition',
131-
'migration/v-model'
131+
'migration/v-model',
132+
'migration/v-bind'
132133
]
133134
},
134135
{

src/guide/migration/v-bind.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: v-bind マージの振る舞い
3+
badges:
4+
- breaking
5+
---
6+
7+
# {{ $frontmatter.title }} <MigrationBadges :badges="$frontmatter.badges" />
8+
9+
## 概要
10+
11+
- **破壊的変更**: v-bind のバインディングの並び順が、レンダリングの結果に影響します。
12+
13+
## イントロダクション
14+
15+
要素に属性を動的にバインドする場合、一般的なシナリオでは、`v-bind="object"` 構文と、同じ要素内にある個別のプロパティの両方を使用します。しかし、これだとマージの優先順位について疑問が残ります。
16+
17+
## 2.x での構文
18+
19+
Vue 2.x では、要素に `v-bind="object"` 構文と同一の個別のプロパティの両方が定義されている場合、個別のプロパティは常に `object` 内のバインディングを上書きします。
20+
21+
```html
22+
<!-- テンプレート -->
23+
<div id="red" v-bind="{ id: 'blue' }"></div>
24+
<!-- 結果 -->
25+
<div id="red"></div>
26+
```
27+
28+
## 3.x での構文
29+
30+
Vue 3.x では、要素に `v-bind="object"` 構文と同一の個別のプロパティの両方が定義されている場合、バインディングの宣言されている順番がそれらをどのようにマージするかを決定します。言い換えると、開発者は個別のプロパティが `object` で定義されているものを常に上書きするのだと決め込むのではなく、希望するマージの振る舞いをコントロールできるようになります。
31+
32+
```html
33+
<!-- テンプレート -->
34+
<div id="red" v-bind="{ id: 'blue' }"></div>
35+
<!-- 結果 -->
36+
<div id="blue"></div>
37+
38+
<!-- テンプレート -->
39+
<div v-bind="{ id: 'blue' }" id="red"></div>
40+
<!-- 結果 -->
41+
<div id="red"></div>
42+
```
43+
44+
## 移行の戦略
45+
46+
もしこの上書きの機能を `v-bind` のために利用しているとしたら、`v-bind` 属性が個別のプロパティより前に定義されているか確認することを推奨します。

0 commit comments

Comments
 (0)