The Wayback Machine - https://web.archive.org/web/20190322235143/https://github.com/vuejs/vue/issues/9707
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
Closed

Different behaviors of Arrow function and function #9707

zhangenming opened this Issue Mar 15, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

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 " rel="nofollow">here.

@Justineo Justineo added the bug label Mar 15, 2019

Justineo added a commit to Justineo/vue that referenced this issue Mar 15, 2019

@Justineo Justineo added the has PR label Mar 15, 2019

@DanielDanaee

This comment has been minimized.

Copy link

DanielDanaee commented Mar 15, 2019

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) }

yyx990803 added a commit that referenced this issue Mar 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.