<div class="col-md-8">
<va-input label="Address 1"
v-model="Address1"
id="address"
class="inp">
</va-input>
</div>
below i am calling api to get data. after getting i need to set value to above input field.
document.getElementById("address").value =res.data[0].address1,
but the above code is not working.
Try using the ref
property, see here: https://v2.vuejs.org/v2/api/#ref Basically would look something like:
<va-input label="Address 1"
v-model="Address1"
id="address"
class="inp"
ref="inputRef"
>
</va-input>
...
this.$refs.inputRef.$el.value = ...
You may need to dig a little into the structure but from the $el
you can access the element.
You need to add this data to the "data" of the component, just create :
`data() {
return {
Address1: ''
}
}`
and at the created()
or anywhere you want to assign this value : this.Adress1 = res.data[0].address1
Basically this is the vue way of doing these kind of things,and using the v-model properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.