0
<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.

3
  • 2
    this is not an vuejs way. Commented Dec 19, 2019 at 8:00
  • Change the model value Address1 and not by directly manipulating dom. Ex: this.Address1 = res.data[0].address1 Commented Dec 19, 2019 at 8:03
  • Pavan, do you have the Address1 variabled in the data field? Commented Dec 19, 2019 at 8:26

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

console log the $el and see exactly where you are, then target the child element you need
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.