vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

Home Page:https://vuejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

lidlanca opened this issue · comments

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