【发布时间】:2018-11-09 05:06:08
【问题描述】:
我正在尝试从 Promise 回调中更改我的 Vue 数据, 并且由于某种原因,我看不到模板中的值变化,
我看到了这个问题how to update a vue's property in a promise call back?
我已将this 更改为正确的,但我仍然看不到模板中的值发生变化。
这是我的模板:
<template>
{{ sites }}
</template>
这是我的脚本:
data: () => ({
sites: {}
}),
methods: {
initialize(snapshot) {
let _this = this
snapshot.forEach((site) => {
convert(site.data())
.then(converted => {
_this.sites[site.id] = converted
})
})
}
}
知道为什么我的数据不会改变吗?
【问题讨论】:
-
那里有什么转换?
-
这是一个异步函数,可将所有 firestore DocumentReference 转换为 JSON:stackoverflow.com/questions/50597797/…
-
您确定 convert 没有拒绝承诺(
then回调中的console.log(converted)实际上输出了您期望的内容)吗? -
是的,确实如此……
标签: javascript vue.js vuejs2