Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error kebabcase event name #20

Closed
QingWei-Li opened this issue Aug 23, 2016 · 7 comments
Closed

Compile error kebabcase event name #20

QingWei-Li opened this issue Aug 23, 2016 · 7 comments

Comments

@QingWei-Li
Copy link
Contributor

<compo on-event-name={ this.handlerEvent } />

console

SyntaxError: Unexpected token (68:17)
@egoist
Copy link
Contributor

egoist commented Oct 8, 2016

I can't reproduce this.

@QingWei-Li
Copy link
Contributor Author

repo: https://github.com/QingWei-Li/vue-jsx-bug

var Compo = {
  render(h) {
    return <button on-click={ () => this.$emit('handle-event') }>click me</button>
  }
}

export default {
  components: { Compo },

  data () {
    return {
      msg: 'Hello Vue!'
    }
  },
  render(h) {
    return (
      <div id="app">
        <h1>{ this.msg }</h1>
        <Compo on-handle-event={ () => console.log(12) }></Compo>
      </div>
    )
  }
}

console

App.js Unexpected token (41:18)
You may need an appropriate loader to handle this file type.
|         {
|           on: {
|             handle-event: function handleEvent() {
|               return console.log(12);
|             }
 @ ./src/main.js 2:0-24
 @ multi main

@egoist
Copy link
Contributor

egoist commented Oct 8, 2016

JSX on-[event] only supports these events, custom events are not supported.

@QingWei-Li
Copy link
Contributor Author

but, it's work

var Compo = {
  render(h) {
    return <button on-click={ () => this.$emit('handleevent') }>click me</button>
  }
}

export default {
  components: { Compo },

  data () {
    return {
      msg: 'Hello Vue!'
    }
  },
  render(h) {
    return (
      <div id="app">
        <h1>{ this.msg }</h1>
        <Compo on-handleevent={ () => console.log(12) }></Compo>
      </div>
    )
  }
}

@egoist
Copy link
Contributor

egoist commented Oct 8, 2016

Oops 😅, I just tested on a wrong component, just use camel case instead

@sxy1992
Copy link

sxy1992 commented May 14, 2018

ohh,I also encountered this problem, thank you for your answer

@JimmyLv
Copy link

JimmyLv commented Nov 14, 2018

For someone who want to listen some non-native events of component, maybe it comes from 3rd party library:

you have to use on-xxx like on-move, on-start, on-end...

<Draggable
                list={this.editors}
                onChange={this.onChange}
                on-start={this.onStart}
                on-end={this.onEnd}
                move={this.onMove}
</Draggable>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants