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

Different behaviors of Arrow function and function #9707

Closed
zhangenming opened this issue Mar 15, 2019 · 2 comments · Fixed by #9709
Closed

Different behaviors of Arrow function and function #9707

zhangenming opened this issue Mar 15, 2019 · 2 comments · Fixed by #9709

Comments

@zhangenming
Copy link

zhangenming commented Mar 15, 2019

Version

2.6.8

Reproduction link

https://codepen.io/zhangenming/pen/GexZQK

Steps to reproduce

    <input :value="price" @input="e=>price=e.target.value">

Compiled:

    with(this){return _c('input',{domProps:{"value":price},on:{"input":e=>price=e.target.value}})}
    <input :value="price" @input="function f(e){price=e.target.value}">// this wont' be work

Compiled:

    with(this){return _c('input',{domProps:{"value":price},on:{"input":function($event){function f(e){price=e.target.value}}}})}

What is expected?

can be work

What is actually happening?

this wont' be work

@Justineo
Copy link
Member

Justineo commented Mar 15, 2019

I helped re-formatted your issue and fixed a typo.

It seems that the template compiler is not generating correct code with function literals with a function name.

See the difference here.

@DanielDanaee
Copy link

Why would you expect this to work? directive values should be method names or methods only.

Have a look at the following part of the documentation:

https://vuejs.org/v2/guide/events.html#Method-Event-Handlers

This is probably what you should be doing:

<input :value="price" @input="getTargetValue(e)">

getTargetValue(e){ return (this.price = e.target.value) }

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

Successfully merging a pull request may close this issue.

3 participants