Point for thought, now that this.$el and this.$refs are deprecated accessing the DOM might need a well rounded solution #9500
Unanswered
lyle45
asked this question in
Ideas / Proposals
Replies: 1 comment 1 reply
-
Here's an article how to access |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Point for thought, now that
this.$el
andthis.$refs
are deprecated or removed from Vue 3, accessing the DOM get's much harderTake for example very simple situations where you'd want to access the DOM of QPage to attach events programmatically, or maybe you want to focus on QBtn after an action or want to set the caret inside a QInput as discussed and solved specifically here
In Vue 2, this was a relatively easy task,
If I wanted to measure the width and height of QCard I could easily do
this.$refs.myCard.$el.clientHeight
or even the riskierthis.$refs.myQInput.$refs.input
to access native input elementThere are many reasons we'd need access to the DOM and I certainly don't expect QBtn to implement focus() method or any other specific solutions
This is a problem with whole Vue 3 IMO and not specific to Quasar, but might be preemptively solved or discussed here
So my general direction for solution for this was having all or most components expose
getRootElement()
method systematically and others should also havegetNativeElement()
if relevant. This could relatively easily be implemented with shared composables, but the template ref part would still need to be implemented in all components individuallyThe only oversight I currently think of for this, and the reason
this.$el
was removed from Vue 3, is that components can now have more then 1 root element. Not sure of best way to solve this systematically but simplest solution would be to simply return an array of refs forgetRootElement()
. Maybe it should always return array for consistencyI would love to here thoughts on this as I mulled over it for some time. I truly think this might have been an oversight on the Vue's team front
Beta Was this translation helpful? Give feedback.
All reactions