Skip to content

Directives

Vue JSX Vapor provides full support for Vue's built-in directives within JSX syntax.

DirectiveVueVolar
v-if, v-else-if, v-else
v-slot, v-slots
v-for
v-model
v-html, v-text/
v-once/

Dynamic Arguments

Variables can be used as directive arguments. Since JSX does not support the [] syntax used in Vue templates, use $ as a substitute.

Modifiers

Modifiers are special postfixes denoted by _ that indicate a directive should be bound in a particular way. Since JSX does not support the . character in attribute names, use _ as a substitute.

tsx
<form onSubmit_prevent>
  <input v-model_number={value} />
</form>

v-if, v-else-if, v-else

Conditional rendering directives work seamlessly with proper type narrowing support.

tsx
export default ({  = 0 }) => {
  return (
    <>
      < v-if={ === 0}>{}</>

      < v-else-if={ === 1}>{}</>

      < v-else>{}</>
    </>
  )
}

v-for

List rendering directive for iterating over arrays or ranges.

tsx
export default () => (
  < v-for={(, ) in 4} ={}>
    {}
  </>
)

v-slot, v-slots

WARNING

Default parameter values in slot scope destructuring (e.g., v-slot={({ foo = '' })}) are not supported due to AST generation limitations.

tsx
const  = () => {
  <{
    : () => any
    : (: { : number }) => any
    : (: { : boolean }) => any
  }>()
   < />
}

export default () => (
  <>
    default slot
    <template v-slot:s={{  }}>
      {}
    </template>
  </>
)
tsx
const  = () => {
  <{
    : () => any
    : (: { : number }) => any
    : (: { : boolean }) => any
  }>()
   < />
}

export default () => (
  <
    ={{
      : () => <>default slot</>,
      : ({  }) => <>{}</>,
    }}
  />
)

v-model

Two-way binding directive with support for dynamic model names and modifiers.

tsx
import {  } from 'vue'

const  = () => {
  const  = <string>('model')
  const  = <string[]>('models')
   < />
}

export default () => {
  const  = ('')
  const  = ('model')
  return (
    <
      v-model:$_$={.}
      v-model:m={.}
    />
  )
}