-
-
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, including namespaced attributes (supersedes #2858) #2877
Conversation
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.
I like this! |
Took me some time to respond this because I am not really a fan of this proposal but it wasn't immediately clear to me what turned me off. I tried it out and it just felt weird to me: <comp :a :b></comp> Now I realize it's because of the semantic implication of HTML attributes that have no values - they are usually boolean attributes. An attribute with no value indicates the "presence of an attribute" or "truthiness". Implicitly expanding to a binding overloads this perception. In addition - if a prop in the child component is declared with type |
Forgot to mention though - thanks to both @phanan and @bopjesvla for taking a stab at implementing this. Appreciate your effort and sorry for the late response. |
👍 Perfect explanation, thanks Evan. Edit: Note to self: From now on, whenever I see the word "imply" in my PR, I'll need to take a step back and think twice ;) |
Zen of python, "explicit is better than implicit" ;) |
The solution @sirlancelot proposed in #5835 seems like it should be in this thread:
|
What if we use My actual use case is a little too specific so I am going to use a fictional but simpler use case, where an alert modal can have a <template>
<LinkModal :text="Sign In" :to="'/sign-in'">
You have to sign in first!
</LinkModal>
</template> <template>
<dialog>
<slot></slot>
<router-link ::to >{{ text }}</router-link>
</dialog>
</template> This is more elegant than doing <script setup>
let max = ref(100);
let min = ref(10);
</script>
<template>
<input type="range" ::max ::min>
</template> |
I originally submitted this as a PR to phanan's #2858, but that's probably more trouble than it's worth. This PR includes phanan's original PR:
But it also includes support and tests for attributes with non-word characters other than hyphens as described here: