【发布时间】:2021-11-24 02:03:18
【问题描述】:
我想在从 .vue 文件 (vuejs) 中的 lifeSpanObj 对象获取名称后,在 ui 中每秒更新人名。
<div> {{personName}}</div> // in template using this this(its example not exactly this)
this.lifeSpanObj.forEach((element, i) => {
setTimeout(function () {
this.personName = element.name;
console.log(this.personName);
}, 1000);
});
使用上面的示例,我可以在控制台中打印更新的值,但 UI 没有得到更新。有什么办法可以解决这个问题?
【问题讨论】:
标签: javascript html vue.js settimeout vuejs3