在mounted中拿不到dom元素怎么回事,可能干扰的原因是啥,在查看元素上已经有dom结构了,但就是获取不到,是 null,但是在浏览器控制台能打印出来这个dom
<el-form-item :label="$t('download.templateContent')" >
<div class="question-editor">
<div id="editor-container" ref="editorContainer">
</div>
</div>
</el-form-item>
mounted() {
const dom = document.getElementById('editor-container');
console.log(dom,'找到富文本编辑器了,在mounted中'); 打印出来是 null
用下面这个打印是undefined ,
this.$nextTick(()=>{
// const dom = document.getElementById('editor-container');
const dom = this.$refs.editorContainer
console.log(dom,'找到富文本编辑器了,在mounted中');
})
}