-
-
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
Add support for v-bind:content shorthand (fixes #2843) #2858
Conversation
Nice! Something I just thought of: A second thing, which may be out of the scope of this PR: it'd be nice if custom directives had the ability to enable this behaviour. |
You're right, I overlooked these (especially the first part). Happy to receive your PR. @yyx990803 may or may not approve this feature btw. |
This commit aims to add support for `v-bind:content` shorthand. With this, v-bind with an empty expression will imply the expression to be the directive name, i.e. `v-bind :content` will have the same effect as `v-bind:content="content"`, `:href` will have the same effect as `:href="href"` and so on so forth. Only attribute bindings are affected by this change. Event, transition, class/style bindings remain unchanged.
@@ -716,6 +717,11 @@ function compileDirectives (attrs, options) { | |||
pushDir(dirName, internalDirectives[dirName]) | |||
} else { | |||
arg = dirName | |||
// support for shorthand expression (#2843) | |||
// <div v-bind:content> => <div v-bind:content="content"> | |||
if (!value) { |
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.
Are you sure about this? We don't want this to happen when the value is null
or undefined
?
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'm not sure if this is what you mean, but value
is the expression, not the return value of the expression. So you can still do v-bind:content="null"
.
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.
You're right, that's the rawValue. My bad!
Is namespacing with colons an accepted syntax with Vue? Not sure if that would be accepted. |
Sure. I don't think @yyx990803 is a fan of this change, though. |
All the more reason to not have two PR's about it :-P |
I personally quite like the feature request #2843, so I went ahead and try to support it.
With this commit,
v-bind
with an empty expression will imply the expression to be the directive name, i.e.v-bind :content
will have the same effect asv-bind:content="content"
,:href
will have the same effect as:href="href"
and so on so forth. Note that only attribute bindings are affected by this change. Event, transition, class/style bindings etc. remain untouched.Not sure if I'm missing anything here – all unit tests passed fine, though. Let me know if there's anything to fix or improve, or just close this PR if you don't intend to support the feature.