【发布时间】:2015-06-10 20:26:32
【问题描述】:
我想在 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 调用空手而归——当时该节点不存在。
我什么时候可以确定 Vue 已经创建/更新了 DOM?
【问题讨论】:
标签: javascript dom vue.js