如何在vuejs中为输入字段设置值 [英] how to set value to input field in vuejs
本文介绍了如何在vuejs中为输入字段设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<va-input label="地址 1"v-model="地址 1"id="地址"类=输入"></va-input>
下面我调用 api 来获取数据.获得后,我需要将值设置为上述输入字段.
document.getElementById("address").value =res.data[0].address1,
但是上面的代码不起作用.
解决方案
尝试使用 ref
属性,请参见此处:https://vuejs.org/v2/api/#ref基本上看起来像:
您可能需要深入了解一下结构,但您可以从 $el
访问该元素.
<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://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.
这篇关于如何在vuejs中为输入字段设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文