Skip to content

Directives

Vue built-in directives for JSX.

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

Dynamic Arguments

It is also possible to use a variable in a directive argument. Because JSX doesn't support [] keyword, use $ instead.

Modifiers

Modifiers are special postfixes denoted by a _, which indicate that a directive should be bound in some special way. Because JSX doesn't support . keyword, we use _ instead.

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

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

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

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

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

v-for

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

v-slot, v-slots

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

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

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

v-model

tsx
import {  } from 'vue'

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

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