【发布时间】:2023-03-10 22:05:01
【问题描述】:
所以我试图分配 this.clean = this.cleaner。
结果道具是我要过滤的 20 个对象的数组。我想要一个对象数组,它们只有一个有效的 poster_path 值,并删除那些不符合该要求的对象。因此 .filter()。
props: ['results'],
data() {
return {
clean: []
}
},
mounted() {
this.clean = this.cleaner
},
methods: {
cleaner() {
return this.results.filter(o => o.poster_path !== null)
}
}
问题是使用我的 vue devtool Vue 似乎没有保存 this.cleaner 值。
对于 this.clean 的值,我得到了 {"_custom":{"type":"function","display":"<span>ƒ</span> bound cleaner()"}}。
如果我尝试使用计算值,我会不断收到“(评估期间的错误)”作为 this.clean 的值。
如果我尝试this.clean = this.cleaner(),它只会保存一个空数组。
【问题讨论】:
标签: javascript vue.js computed-properties