[Vuejs]-Input value that's binded with vue does not show up in the dom

0👍

What you’re seeing is normal. Vue treats the value attribute of an <input> specially and sets it as a property rather than as an attribute. Effectively the compiled template uses:

input.value = role.Id

rather than:

input.setAttribute('value', role.Id)

You can see the relevant Vue source code here:

https://github.com/vuejs/vue/blob/98b4d683f578bb09c4e56f35048e49441c590a41/src/compiler/parser/index.js#L837

with the implementation of platformMustUseProp being here:

https://github.com/vuejs/vue/blob/98b4d683f578bb09c4e56f35048e49441c590a41/src/platforms/web/util/attrs.js#L11

If you remove the hidden attribute from the surrounding <td> you should see that the <input> does contain the correct value. It isn’t clear why you need it to have a value attribute, for most practical purposes that shouldn’t matter as everything should be accessing the value using input.value instead.

If the <input> is going to be hidden you may also want to consider using type="hidden" rather than type="text".

0👍

<input type="text" :id="role.Id" name="role[]" :value="role.Id"/> 

Leave a comment