Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript vue js安装的生命周期挂钩中的getElementById将导致null_Javascript_Vue.js - Fatal编程技术网

Javascript vue js安装的生命周期挂钩中的getElementById将导致null

Javascript vue js安装的生命周期挂钩中的getElementById将导致null,javascript,vue.js,Javascript,Vue.js,当我试图用document.getElementById查看id中的内容时,我得到了null。部分守则如下: <input-layout v-if="edit" label="Status" class="grayout"> <u-select v-model='test.status' :options="testStatus" tabindex="14" cl

当我试图用
document.getElementById
查看id中的内容时,我得到了
null
。部分守则如下:

<input-layout v-if="edit" label="Status" class="grayout">
        <u-select v-model='test.status' :options="testStatus" tabindex="14" class="grayout" id="testStatusDropDown"/>
</input-layout>

<input id="input1" type="checkbox">
最初,我在mounted方法中没有
console.log
语句,这导致
input1
testStatusDropDown的
null
。我理解这一点,因为当这部分代码运行时,这两个元素还不存在。然后我将它们移动到mounted方法中,现在,我可以看到
,但是对于第二个log语句,我得到
null

我访问了vue js挂载的api文档,可以在这里找到:。我可以看到,
mounted
并不保证所有子组件都已安装,因此我需要在
mounted
方法中使用
this.$nextTic
。然而,即使在添加了
this.$nextTick
之后,我仍然存在同样的问题,即
document.getElementById(“testStatusDropDown”)
在我预期的
情况下会导致
null


我的期望不正确吗?我需要做哪些更改才能使
document.getElementById(“testStatusDropDown”)
不返回
null

使用ref引用vuejs中的元素

<input id="input1" ref="input1" type="checkbox">

使用ref引用vuejs中的元素

<input id="input1" ref="input1" type="checkbox">

您是否使用
ref
访问元素?
并在
中安装此。$refs.input1
没有,我的vue知识有限,您可以再扩展一点吗?它用于引用vue中的一个元素您在使用v-Model时不需要getElementById您是否使用了
ref
访问该元素?
并在安装的
中安装了此项。$refs.input1
没有,我的vue知识有限,可以再扩展一点吗?它用于引用vue中的一个元素。当您使用v-model时,您实际上不需要getElementById
this.$refs.input1