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
<pv-highlight="yellow">Highlight this text bright yellow</p>
29
+
<pv-highlight="'yellow'">このテキストを明るい黄色で強調表示します</p>
31
30
```
32
31
33
32
```js
@@ -38,37 +37,38 @@ Vue.directive('highlight', {
38
37
})
39
38
```
40
39
41
-
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:
44
+
45
+
ただし、Vue 3 では、カスタムディレクティブ用のよりまとまりのある API を作成しました。Vue 2 では、似たようなイベントにフックしているにもかかわらず、コンポーネントのライフサイクルメソッドとは大きく異なります。これらを次のように統合しました。
46
46
47
47
- bind → **beforeMount**
48
48
- inserted → **mounted**
49
-
-**beforeUpdate**: new! this is called before the element itself is updated, much like the component lifecycle hooks.
50
-
- update → removed! There were too many similarities to updated, so this is redundant. Please use updated instead.
In Vue 3, we're now supporting fragments, which allow us to return more than one DOM node per component. You can imagine how handy that is for something like a component with multiple lis or the children elements of a table:
As a result, custom directives are now included as part of a virtual DOM node’s data. When a custom directive is used on a component, hooks are passed down to the component as extraneous props and end up in `this.$attrs`.
92
+
```javascript
93
+
bind(el, binding, vnode) {
94
+
constvm=vnode.context
95
+
}
96
+
```
101
97
102
-
This also means it's possible to directly hook into an element's lifecycle like this in the template, which can be handy when a custom directive is too involved:
98
+
Vue 3 では、インスタンスは `binding` の一部になりました。
103
99
104
-
```html
105
-
<div@vnodeMounted="myHook" />
100
+
```javascript
101
+
mounted(el, binding, vnode) {
102
+
constvm=binding.instance
103
+
}
106
104
```
107
105
108
-
This is consistent with the attribute fallthrough behavior, so when a child component uses `v-bind="$attrs"` on an inner element, it will apply any custom directives used on it as well.
0 commit comments