【发布时间】:2025-12-01 05:40:01
【问题描述】:
我正在使用 MongoDB 和 vue.js 来显示我的数据库中的内容,该内容作为具有多个包含其他对象的属性的对象返回。
但问题是vue.js的v-for函数是随机显示内容的。
在我的数据库中,内容按字段创建排序,并保持在这个位置。
当我在this.statics 中获取对象时,如果我 console.log 它,我会按字母排序获得这些字段。但我不明白的是:当我用v-for 显示它时,它们永远不会以相同的顺序出现。
这是我的 vue 代码:
h3 Static elements
.content-wrap(v-if="Object.keys(statics).length > 0")
.menu-admin
.btn(v-for="(content, key) in statics" @click="activeStatic = key") {{key}}
.content(v-for="(content, key) in statics" v-if="key === activeStatic")
h3 {{key}}
.line
.wrap(v-for="(item, keys) in content")
h4 {{keys}}
问题是keys在哪里。
这是返回我的对象的函数:
getStatics(statics) {
Promise.all(Object.keys(statics).map((key) => {
return PartsService.fetchDataWrap({
id: statics[key]
}).then((res) => {
statics[key] = res.data.values
})
})).then(() => {
this.statics = statics
})
},
this.statics 的控制台.log(从不更改):
{__ob__: Observer}
my static bloc: Object
image1: (...)
image2: (...)
text1: (...)
text2: (...)
【问题讨论】:
-
您好,您的问题解决了吗?我有同样的问题并试图解决这个问题,但仍然没有实现。