Skip to content

Explain different ways that props are treated in v3 #1277

Open
@pikax

Description

@pikax

In v3 v-on was merged with props, for that to happen props started with on* are treated as events

<Comp 
        @myEvent="log('myEvent')" 
        @my-event="log('my-event')"
        :onMyEvent="()=>log('onMyEvent')"
  />
  

<! -- CONVERTED TO  --> 
h(Comp, {
      onMyEvent: [
        _cache[0] || (_cache[0] = $event => (log('myEvent'))),
        _cache[1] || (_cache[1] = $event => (log('my-event'))),
        ()=>log('onMyEvent')
      ]
})

playground

You can also declare events as props

defineComponent({
  props: {
    onClick: Function, // similar to emit: ['click']
  }
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionTopics to discuss that don't have clear action items yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions