【发布时间】:2018-04-10 04:47:35
【问题描述】:
我对在异步加载的 vue 模板数据中显示的情况很感兴趣。在我的特殊情况下,我需要显示产品对象的标题属性:
<td class="deals__cell deals__cell_title">{{ getProduct(deal.metal).title }}</td>
但产品当前未加载,因此根本不会呈现标题。我找到了一个可行的解决方案:如果未加载产品,则在解决承诺后调用 getProduct 函数:
getProduct (id) {
if (!this.rolledMetal.all.length) {
this.getRolledMetal()
.then(() => {
this.getProduct(id)
})
return {
title: ''
}
} else {
return this.getRolledMetalById(id)
}
}
但是,也许您知道更优雅的解决方案,因为我认为这个解决方案有点复杂 :)
【问题讨论】:
标签: javascript templates asynchronous vue.js