I think my perception of this as a "hack" mostly refers to "using assignment expressions as attributes". It just doesn't feel right (to me, personally). Sure, it's a thing we've done forever in on* event attributes, but at least the semantics of events do match this better than the semantics of vanilla attributes.
That's pretty much the same as let foo; while (foo = expression) { /* use foo */ } — it's a thing that is frowned upon by many readers and linters, but it's used because the clean way would be annoyingly verbose.
Thanks. I would like to add, though, this is neither dirty nor a hack.
Vue does allow us to create local variables on
this
and just cautions that they won't be reactive (I read it somewhere in the docs).As for setting values, well, it's just like an event handler, where one would do exactly the same:, for example:
@click="item=$event"
I know it feels like a hack, at first looks, because it's too simple, but it's legit.
Perhaps, I cheated a bit by using an attribute named
:set
;)I think my perception of this as a "hack" mostly refers to "using assignment expressions as attributes". It just doesn't feel right (to me, personally). Sure, it's a thing we've done forever in
on*
event attributes, but at least the semantics of events do match this better than the semantics of vanilla attributes.That's pretty much the same as
let foo; while (foo = expression) { /* use foo */ }
— it's a thing that is frowned upon by many readers and linters, but it's used because the clean way would be annoyingly verbose.I hear you.