我正在尝试这个:
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 not a function
。我在看Is it possible to use the computed properties to compute another properties in Vue?,它说这应该是使用其他计算属性的方法。
答案 0 :(得分:1)
这就是我在评论中解释的内容。
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
}
}