-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
select v-model does not set option selected attribute in rendered HTML using SSR #5339
Comments
This is a bit tricky as the current implementation of v-model on So in that sense, this works as intended and it's not really a bug. Though I see the challenge when JS is disabled on the client. So far I don't have a bright idea how this could be improved, besides the workaround already documented. |
@LinusBorg Thanks for the explanation. This sounded to me like
This will correctly set the |
Radio buttons are different, as Vue can evaluate each one on their own during render, and thus can set the checked attribute before mounting the element. The select element on the other hand needs to compare its v-model value to the options children that are created independently from it. Not saying this is not solvable with another approach, just describing the current one and why it works the way it does. |
This also causes select inputs to show empty or the first option selected after the initial browser's render. |
Version
3.2.29
Reproduction link
sfc.vuejs.org/
Steps to reproduce
Create a template with
<select v-model="...">
and some<option :value="...">
elements. And then look at the rendered HTML. There will never be aselected
attribute on theoption
elements.When loading the SSR rendered page with disabled JavaScript it will always select the first option, because no
option
in the HTML is actuallyselected
.What is expected?
Similar behavior to
<input v-model="...">
. Forinput
elements this will insert avalue="..."
attribute.Though
<select v-model="...">
should insert aselected
attribute for the selected option element. (Or elements when using<select multiple>
).What is actually happening?
No
selected
attribute is added to the SSR rendered HTML.A workaround is to set
:selected
manually:The text was updated successfully, but these errors were encountered: