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
Copy file name to clipboardExpand all lines: src/api/sfc-script-setup.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,31 @@ import * as Form from './form-components'
127
127
</template>
128
128
```
129
129
130
+
## Using Custom Directives
131
+
132
+
Globally registered custom directives just work as normal. Local custom directives don't need to be explicitly registered with `<script setup>`, but they must follow the naming scheme `vNameOfDirective`:
133
+
134
+
```vue
135
+
<script setup>
136
+
const vMyDirective = {
137
+
beforeMount: (el) => {
138
+
// do something with the element
139
+
}
140
+
}
141
+
</script>
142
+
<template>
143
+
<h1 v-my-directive>This is a Heading</h1>
144
+
</template>
145
+
```
146
+
147
+
If you're importing a directive from elsewhere, it can be renamed to fit the required naming scheme:
148
+
149
+
```vue
150
+
<script setup>
151
+
import { myDirective as vMyDirective } from './MyDirective.js'
0 commit comments