You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**bind** - Occurs once the directive is bound to the element. Occurs only once.
21
-
-**inserted** - Occurs once the element is inserted into the parent DOM.
22
-
-**update** - This hook is called when the element updates, but children haven't been updated yet.
23
-
-**componentUpdated** - This hook is called once the component and the children have been updated.
24
-
-**unbind** - This hook is called once the directive is removed. Also called only once.
20
+
-**bind** - ディレクティブが要素にバインドされると発生します。一度だけ発生します。
21
+
-**inserted** - 要素が親 DOM に挿入された後に発生します。
22
+
-**update** - 要素が更新されたときに呼び出されますが、子はまだ更新されていません。
23
+
-**componentUpdated** - コンポーネントと子が更新されると呼び出されます。
24
+
-**unbind** - ディレクティブが削除されると呼び出されます。 1回だけ呼び出されます。
25
25
26
-
Here’s an example of this:
26
+
この例を次に示します。
27
27
28
28
```html
29
-
<pv-highlight="'yellow'">Highlight this text bright yellow</p>
29
+
<pv-highlight="'yellow'">このテキストを明るい黄色で強調表示します</p>
30
30
```
31
31
32
32
```js
@@ -37,37 +37,38 @@ Vue.directive('highlight', {
37
37
})
38
38
```
39
39
40
-
Here, in the initial setup for this element, the directive binds a style by passing in a value, that can be updated to different values through the application.
In Vue 3, however, we’ve created a more cohesive API for custom directives. As you can see, they differ greatly from our component lifecycle methods even though we’re hooking into similar events. We’ve now unified them like so:
It's generally recommended to keep directives independent of the component instance they are used in. Accessing the instance from within a custom directive is often a sign that the directive should rather be a component itself. However, there are situations where this actually makes sense.
In Vue 3, the instance is now part of the `binding`:
98
+
Vue 3 では、インスタンスは `binding` の一部になりました。
98
99
99
100
```javascript
100
101
mounted(el, binding, vnode) {
@@ -103,5 +104,5 @@ mounted(el, binding, vnode) {
103
104
```
104
105
105
106
:::warning
106
-
With [fragments](/guide/migration/fragments.html#overview)support, components can potentially have more than one root nodes. When applied to a multi-root component, directive will be ignored and the warning will be thrown.
0 commit comments