我想在Vue创建内部<input>
元素后访问它:
<li v-repeat="subtask: subtasks">
<input v-model="subtask.name" type="text">
</li>
但是,此代码不起作用:
/* add a new item (that in turn will create a new DOM node) */
subtasks.push({
name: 'wash the dishes',
id: 'box-123'
});
/* ... Around now, Vue should get busy creating the new <li> ... */
/* Now the element should exist, but it doesn't */
console.log(document.getElementById('box-123'));
// --> null
然而,getElementById
次呼叫空手而归—— node 当时不存在.
我什么时候可以确定Vue已经创建/更新了DOM?