Skip to content

Commit eb244fd

Browse files
docs: add a section about using custom directives in render functions (#863)
1 parent 9436d6c commit eb244fd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/guide/render-function.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,27 @@ Similarly, if the value passed to `is` is a component options object then there'
530530

531531
Much like a `<template>` tag, a `<component>` tag is only required in templates as a syntactical placeholder and should be discarded when migrating to a `render` function.
532532

533+
### Custom Directives
534+
535+
Custom directives can be applied to a VNode using [`withDirectives`](/api/global-api.html#withdirectives):
536+
537+
```js
538+
const { h, resolveDirective, withDirectives } = Vue
539+
540+
// ...
541+
542+
// <div v-pin:top.animate="200"></div>
543+
render () {
544+
const pin = resolveDirective('pin')
545+
546+
return withDirectives(h('div'), [
547+
[pin, 200, 'top', { animate: true }]
548+
])
549+
}
550+
```
551+
552+
[`resolveDirective`](/api/global-api.html#resolvedirective) is the same function that templates use internally to resolve directives by name. That is only necessary if you don't already have direct access to the directive's definition object.
553+
533554
## JSX
534555

535556
If we're writing a lot of `render` functions, it might feel painful to write something like this:

0 commit comments

Comments
 (0)