[RFC] v-scope
as template-local identifier aliasing (sugar for v-for
)
#682
matthew-dean
started this conversation in
RFC Discussions
Replies: 2 comments
-
Related: vuejs/core#7218 |
Beta Was this translation helpful? Give feedback.
0 replies
-
It's more practical to create a new component in this case. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background
One thing that is a common request online is scoping a variable in a template to a particular section of markup. For example, imagine we have an object getter that returns strong TypeScript types when requested by path, like this:
Say we're binding values of lots of these paths for a form, and end up with markup like:
Now, one thing we could do is elevate ALL model references to declared variables in our
setup
script, but that just moves the verbosity someplace else, and adds a layer of abstraction. A common solution online to get strong TypeScript typing and scoping is to do something like this:In all
name
references, it will be strongly typed. However, this has some issues:eslint-plugin-vue
's default recommended eslint settings, because of#2
, will enforce a key in all cases.Proposal:
v-scope="{ key: 'value' }"
Instead, the above could be replaced like this:
v-scope
would allow key / value pairs (defined as an object) that would be referenceable only in this template scope. This would be better than other hacks found on StackOverflow which use an arbitrary key like:set="name = getTyped(model, 'a.deeply.bound.path.name')"
, which will scope a variable to the entire template (so can be over-written if used more than once), and which will function in a JavaScript environment, but will fail TypeScript type-checking.Beta Was this translation helpful? Give feedback.
All reactions