-
-
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
A short syntax for v-bind .prop modifier #7582
Comments
This would be useful with my Custom Elements, which accept either attributes or props of the same name, and adding a whole extra |
Worth noting, an attribute prefixed with |
Although interestingly, if a DOM element starts with an attribute like document.body.innerHTML = `<div .foo="bar">inspect me to see .foo attribute</div>`
document.body.children[0].getAttribute('.foo') // "bar", it exists!
document.body.children[0].setAttribute('.foo', '') // Uncaught DOMException: Failed to execute 'setAttribute' on 'Element': '.foo' is not a valid attribute name. |
That's a great idea. Will consider this in 2.6. |
What do you think of In my case, I can do stuff like following with my elements: el.rotation = [0, 30, 0]
// or
el.rotation.y = 30 so the following could be convenient in the template: <i-sphere .rotation.y="30"></i-sphere> |
Anything more than a shorthand is beyond the original scope of this proposal. And no, I don't think magic path extensions are a good idea. That's like reaching into the child component's private state. |
It's interesting, because then, do you suggest that I refactor my custom elements to have attributes and properties like the following? <i-mesh .rotation="" .rotation-y="" .rotation-x="" .rotation-z=""> and el.rotation = [...];
el.rotationY = ...;
el.rotationX = ...;
el.rotationZ = ...; It makes the JavaScript API less clean, but I can live with it. I could even automatically map |
Or |
Yeah, it's easy to work around. I was concerned about performance: <!-- creates a new object every animation frame, causes more GC -->
<i-mesh .rotation="{ x, y, z }"></i-mesh> So, I'll just do it like follows by adding more properties to my custom elements: <!-- passes only a number every animation frame -->
<i-mesh .rotation-y="y"></i-mesh> Plus, this makes it clear which attributes map directly to properties, without reaching into places that are not represented as attributes. Maybe this is a good thing! Looking forward to the prefix |
Well, maybe it's moot, because it's also possible that |
Closed via d2902ca |
What problem does this feature solve?
Make things shorter and easier to write.
What does the proposed API look like?
:foo="bar"
is a syntax shortcut forv-bind:foo="bar"
.Similarly,
.foo="bar"
would be a nice shortcut for:foo.prop="bar"
(and the leading.
even makes sense!).The text was updated successfully, but these errors were encountered: