我正在尝试这个:
props: ["gameState"],
computed: {
cards() {
return this.gameState.playerCards
},
rows() {
let cards = this.cards();
let max = 6;
if (cards.length <= max)
return [cards]
var mid = Math.ceil(cards.length / 2);
let return_value = [cards.slice(0, mid), cards.slice(mid)]
return return_value
}
}
但它告诉我 this.cards 不是一个函数
。我在看Is it possible to use the computed properties to compute another properties in Vue?这表示这应该是使用其他计算属性的方式。
最佳答案
这就是我在评论中解释的内容。
computed: {
cards() {
return this.gameState.playerCards
},
rows() {
let cards = this.cards;
// if cards is ever undefined (maybe its populated asynchronously),
// cards.length will blow up. So, check here and return a sane
// value when it's undefined
if (!cards) return []
let max = 6;
if (cards.length <= max)
return [cards]
var mid = Math.ceil(cards.length / 2);
let return_value = [cards.slice(0, mid), cards.slice(mid)]
return return_value
}
}
关于javascript - 如何在计算中使用其他计算属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47403102/