zl2003cn
zl2003cn

Reputation: 485

Using spread operator with event listeners in VueJS 2 and JSX

Here is a simple version for my problem:

render (h) {
  let events = {onClick: handleClick}
  return (<div {...events}></div>)
}

onClickevent was not add to the div element, and spread operator works well with class and style attribute but not any of the event listener bindings (starts with on or nativeOn). Can somebody explain why and offer me a solution that I can bind arbitrary amount of event on a element?

Upvotes: 2

Views: 1229

Answers (1)

Sergey Orlov
Sergey Orlov

Reputation: 331

it should be like this:

render (h) {
  const hi = function () {
    console.log('hello')
  }
  return (
    <div { ...{ on: {click: hi} } } > click me! </div>
  )
}

Here the link to babel-plugin-transform-vue-jsx issues

Upvotes: 3

Related Questions