vuejs / rfcs

RFCs for substantial changes / feature additions to Vue core
4.87k stars 546 forks source link

Script refs #214

Closed johnsoncodehk closed 3 years ago

johnsoncodehk commented 4 years ago

We understand that most users accept the use of .value, but we still hope that we can have some solution for users who do not like .value.

Rendered: 中文 | English

If you want to try: <script refs> requires additional IDE support, I implemented it in another Vue Language Service plugin For the preview you don't need to compile, but if you want, you can use @cereschen webpack plugin

jods4 commented 4 years ago

How does that work with imported functions? How does the compiler know if the function wants a raw value or a ref?

import { square } from "./math.js";
ref x = 3
// What is passed to square? A ref or a number? 
// Both options are common, how can we have the opposite behavior?
square(x)
johnsoncodehk commented 4 years ago

How does that work with imported functions? How does the compiler know if the function wants a raw value or a ref?

import { square } from "./math.js";
ref x = 3
// What is passed to square? A ref or a number? 
// Both options are common, how can we have the opposite behavior?
square(x)

You can't, ref will alway transform to raw value and pass to function: https://github.com/cereschen/rfcs/blob/script-refs/active-rfcs/0000-sfc-script-refs.md#dont-transform Before we has this feature: https://github.com/cereschen/rfcs/blob/956e74288552b699dafd83f0706430f86c11e0fb/active-rfcs/0000-sfc-script-no-ref.md#dont-transform In order to reduce the magic, it was removed, welcome any good idea. :)