2 回答

TA贡献1836条经验 获得超13个赞
正如其他人所提到的,当您使用数据来驱动模板时,Vue 的效果最好。直接操作 DOM 是一种反模式。
例如,为要显示的信息使用数据属性,并在查询完成时为其分配一个值
<p>{{ profileCount }}</p>
export default {
data: () => ({ profileCount: null }),
async created () {
const { size } = await db.collection("Profile").get()
this.profileCount = size
}
}

TA贡献1886条经验 获得超2个赞
不要像通常在使用vanilla JS(纯 javascript)时那样直接操作 DOM,或者jQuery因为在使用时vue.js遵循反应模式很好。
<template>
<p> {{ users }} </p>
</template>
<script>
export default {
data() {
return {
users: 0
};
},
// you can use created or mounted, see which works
created() {
db.collection("Profile").get().then((res) => {
this.users = res.size
})
}
};
</script>
添加回答
举报