From 1c69b59b415decd5d0b8d20f332af5e85aacc630 Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Wed, 7 Apr 2021 20:07:16 +0900 Subject: [PATCH 1/4] Add an original document --- .../migration/attrs-includes-class-style.md | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/guide/migration/attrs-includes-class-style.md diff --git a/src/guide/migration/attrs-includes-class-style.md b/src/guide/migration/attrs-includes-class-style.md new file mode 100644 index 00000000..dbb6a5ce --- /dev/null +++ b/src/guide/migration/attrs-includes-class-style.md @@ -0,0 +1,69 @@ +--- +title: $attrs includes class & style +badges: + - breaking +--- + +# `$attrs` includes `class` & `style` + +## Overview + +`$attrs` now contains _all_ attributes passed to a component, including `class` and `style`. + +## 2.x Behavior + +`class` and `style` attributes get some special handling in the Vue 2 virtual DOM implementation. For that reason, they are _not_ included in `$attrs`, while all other attributes are. + +A side effect of this manifests when using `inheritAttrs: false`: + +- Attributes in `$attrs` are no longer automatically added to the root element, leaving it to the developer to decide where to add them. +- But `class` and `style`, not being part of `$attrs`, will still be applied to the component's root element: + +```vue + + +``` + +when used like this: + +```html + +``` + +...will generate this HTML: + +```html + +``` + +## 3.x Behavior + +`$attrs` contains _all_ attributes, which makes it easier to apply all of them to a different element. The example from above now generates the following HTML: + +```html + +``` + +## Migration Strategy + +In components that use `inheritAttrs: false`, make sure that styling still works as intended. If you previously relied on the special behavior of `class` and `style`, some visuals might be broken as these attributes might now be applied to another element. + +## See also + +- [Relevant RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0031-attr-fallthrough.md) +- [Migration guide - `$listeners` removed](./listeners-removed.md) +- [Migration guide - New Emits Option](./emits-option.md) +- [Migration guide - `.native` modifier removed](./v-on-native-modifier-removed.md) +- [Migration guide - Changes in the Render Functions API](./render-function-api.md) From 3bdfc206a01c6dbbe72ca4674cb796cb2d36bead Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Thu, 8 Apr 2021 20:15:23 +0900 Subject: [PATCH 2/4] Add sidebar menu --- src/.vuepress/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/.vuepress/config.js b/src/.vuepress/config.js index 1d29ce3b..5c816565 100644 --- a/src/.vuepress/config.js +++ b/src/.vuepress/config.js @@ -114,6 +114,7 @@ const sidebar = { 'migration/array-refs', 'migration/async-components', 'migration/attribute-coercion', + 'migration/attrs-includes-class-style', 'migration/custom-directives', 'migration/custom-elements-interop', 'migration/data-option', From c580e9502151ba0f305821e2c79a3fb2e40a578a Mon Sep 17 00:00:00 2001 From: Naoki Endoh Date: Fri, 9 Apr 2021 12:00:16 +0900 Subject: [PATCH 3/4] Replace with Japanese translation --- .../migration/attrs-includes-class-style.md | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/guide/migration/attrs-includes-class-style.md b/src/guide/migration/attrs-includes-class-style.md index dbb6a5ce..8dbdf51d 100644 --- a/src/guide/migration/attrs-includes-class-style.md +++ b/src/guide/migration/attrs-includes-class-style.md @@ -1,23 +1,24 @@ --- -title: $attrs includes class & style +title: class と style を含む $attrs badges: - breaking --- -# `$attrs` includes `class` & `style` +# `class` と `style` を含む `$attrs` -## Overview +## 概要 -`$attrs` now contains _all_ attributes passed to a component, including `class` and `style`. +`$attrs` は、 `class` と `style` を含む、コンポーネントに渡されるすべての属性が含まれるようになりました。 -## 2.x Behavior +## 2.x の挙動 -`class` and `style` attributes get some special handling in the Vue 2 virtual DOM implementation. For that reason, they are _not_ included in `$attrs`, while all other attributes are. +`class` と `style` 属性は、Vue 2 の仮想 DOM 実装でいくつかの特別な処理が行われます。そのため、他のすべての属性は含まれていますが、これらは `$attrs` に含まれていません。 -A side effect of this manifests when using `inheritAttrs: false`: +この副作用は、 `inheritAttrs: false` を使用した場合に明らかになります: -- Attributes in `$attrs` are no longer automatically added to the root element, leaving it to the developer to decide where to add them. +- `$attrs` に含まれる属性は、自動的にルート要素に追加されなくなり、どこに追加するかは開発者の判断に委ねられます。 - But `class` and `style`, not being part of `$attrs`, will still be applied to the component's root element: +- しかし、 `class` と `style` は、 `$attrs` の一部ではないので、コンポーネントのルート要素に適用されます: ```vue