vuejs / rfcs

RFCs for substantial changes / feature additions to Vue core
4.85k stars 551 forks source link

Ref sugar (take 2) #368

Closed yyx990803 closed 2 years ago

yyx990803 commented 2 years ago

Summary

Introduce a compiler-based syntax sugar for using refs without .value:

<script setup>
  // declaring a variable that compiles to a ref
  let count = $ref(1)

  console.log(count) // 1

  function inc() {
    // the variable can be used like a plain value
    count++
  }
</script>

<template>
  <button @click="inc">{{ count }}</button>
</template>
yyx990803 commented 2 years ago

The original proposal has been updated and merged with props destructure. The discussion is still in https://github.com/vuejs/rfcs/discussions/369