Replies: 3 comments 5 replies
-
there is https://v3.vuejs.org/api/sfc-script-setup.html already |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Now thinking, As the object returned by Please notice that it uses https://codesandbox.io/s/this-ux95o I still prefer Composition API over it (especially with ref sugar), though. |
Beta Was this translation helpful? Give feedback.
-
Summary
Using a variable with data, to reduce the use of functions.
Avoid having to return an object with options from
setup()
.Not to import
ref()
orreactive()
Basic example
Motivation
Importing and using the
ref
andreactive
functions creates a lot of boilerplate.Also variables, if not specially named, can get lost among the others if the component is large.
This is a suggestion to shorten the boilerplate and make it easier for newcomers to understand.
Also, there will be a place where the data of this component will be stored, similar to the
data()
function.Detailed design
Since we use Proxy, all variables that will get here can automatically be made reactive at the creation stage.
You won't have to import
ref
,reactive
, you can also get rid of the.value
syntax for simple types.Same with functions
Also from setup it will not be necessary to return the object, because it is already stored in the component.
Adoption strategy
This feature is opt-in. Existing code is unaffected.
Beta Was this translation helpful? Give feedback.
All reactions