Javascript Vue this.$refs返回一个看起来为空但在检查器中具有值的对象
我使用watch方法来观察道具的变化,当这种情况发生时,我想自动聚焦一个输入元素,我使用以下代码Javascript Vue this.$refs返回一个看起来为空但在检查器中具有值的对象,javascript,vue.js,Javascript,Vue.js,我使用watch方法来观察道具的变化,当这种情况发生时,我想自动聚焦一个输入元素,我使用以下代码 watch: { currentBookEntry: { immediate: true, handler: function() { console.log(this.$refs) console.log(this.$refs.inputElement) } } }, this.$refs.inputEl
watch: {
currentBookEntry: {
immediate: true,
handler: function() {
console.log(this.$refs)
console.log(this.$refs.inputElement)
}
}
},
this.$refs.inputElement返回未定义,this.$refs返回一种空对象,在屏幕截图中,您看到它没有inputElement数据,但如果我在inspector中单击它打开,我确实看到了那里的数据,这是什么样的源代码
等到下一个DOM更新周期之后
this.$nextTick(function(){
console.log(this.$refs.inputElement)
})
等到下一个DOM更新周期之后
this.$nextTick(function(){
console.log(this.$refs.inputElement)
})