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

@onclick="v+=1" for ref v declared as var/let does not increment. <script setup> #3625

Closed
lidlanca opened this issue Apr 17, 2021 · 0 comments · Fixed by #3626
Closed

@onclick="v+=1" for ref v declared as var/let does not increment. <script setup> #3625

lidlanca opened this issue Apr 17, 2021 · 0 comments · Fixed by #3626
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working scope: script-setup scope: sfc

Comments

@lidlanca
Copy link
Contributor

lidlanca commented Apr 17, 2021

Version

3.0.11

Reproduction link

sfc playground

Steps to reproduce

trigger @click for button with v+=1 expression two times.
1st time it will reset v to 1
2nd time and onward it will stay 1

What is expected?

it is expected that v+=1 will increment value of v by 1 every time @click is triggered.

The same way v=v+1 or v++ works

What is actually happening?

v+=1 always sets the value to 1 and does not increment


vue: v3.0.11

for a var/let v = ref()

v += 1 is compiled to:

    _createVNode("button", {
      onClick: _cache[3] || (_cache[3] = $event => (_isRef(v) ? v.value = 1 : v+=1))
    }, "v += 1"),

for a const c = ref()

 _createVNode("button", {
      onClick: _cache[6] || (_cache[6] = $event => (c.value += 1))
    }, "c += 1")
@HcySunYang HcySunYang added 🐞 bug Something isn't working 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: sfc labels Apr 18, 2021
Sociosarbis pushed a commit to Sociosarbis/vue-next that referenced this issue Apr 19, 2021
yyx990803 pushed a commit that referenced this issue May 28, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working scope: script-setup scope: sfc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants