-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: fix #6913, feat($compiler): add support of v-local directive to provide a way to… #7325
Conversation
1908535
to
5fe535a
Compare
describe('Directive v-local', () => { | ||
it('should work', () => { | ||
const vm = new Vue({ | ||
template: '<div><span v-local="v as foo.bar">{{v.baz}}</span></div>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather see the other way around foo.bar as v
or a different more js friendly syntax (which allows to create multiple variables):
<div v-local:v="foo.bar" v-lobal:baz="foo.bar.baz">
At the end, it would still be valid js. It can even be aliased to something like <div $v="foo.bar"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are my thoughts on the feature. That being said, I feel that this crosses the line of Javascript/Magic even though I see when it can be comfortable to use 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
5fe535a
to
6d4e42c
Compare
) | ||
}) | ||
|
||
it('generate v-local directive with v-for', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need another test for combining v-for, scoped slot and v-local together as scoped vFor is handled separately IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated,
- add some test for scoped slot
- fix invalid v-local in scoped-slot with template tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some deeper thoughts, v-local
might be harder than I originally estimated. The root problem is it adds a new way to introduce new variable in template. After this, we will have three way to introduce new variables:
- v-for
- slot-scope
- v-local
With 1 and 2 we already have some ordering issue, #6817. I would say more variable introduction isn't scalable in current implementation. For example, <div v-local:items="foo.deep.prop" v-for="item in items">
is still missing in test. And supporting such usage will require yet another patch in genFor
.
👋 community user here adding thoughts i appreciate the interest in this feature and also respect your time in creating, however I don't think that increasing the scope, complexity and maintenance of Vue core is worth the cost of this feature because it could be handled in userland. |
6d4e42c
to
daf1c9d
Compare
… set local variable in template fix vuejs#6913
daf1c9d
to
39a755f
Compare
I'm closing this since I share a similar concern (the tradeoff between codebase complexity vs. the benefits). Instead, I think we should look at how to make scoped slots syntax even simpler so a less-verbose userland helper component becomes possible. |
I think this one should be reconsidered. I think people are moving to Alpine.js because it's so easy to sprinkle declarative rendering in server-side templates. At the very minimum, I'd suggest some documentation on how to do this in Vue.js. As an example, you can make "Django components" like this... In
In
Note that I'd love to do this in Vue.js, but it's not clear (at least to me) how to do so with the current docs. Please let me if I'm missing something. Thanks! |
I agree with @pandichef that this should be reconsidered. This was closed before the release of petite-vue and it would make it easier for people converting from petite-vue to the full Vue experience. |
… set local variable in template
fix #6913
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information: