부모 구성 요소의 데이터를 업데이트 할 때 소품이 업데이트되지 않는 이유가 확실하지 않습니다. 나는 그것을 바이올린으로 시도했지만 https://jsfiddle.net/f3w69rr6/1/이 작동하지만 내 응용 프로그램에서는 작동하지 않습니다.Vue 계산 된 속성이 업데이트 된 소품으로 업데이트되지 않음
<PlayerCards :gameState="gameState" :hand="gameState.playerHand" />
아이 :
부모 :를 통해 자녀에 데이터를 넣어
methods: {
addToHand(index) {
let card = this.gameState.playerDeck.splice(index, 1)
if (this.gameState.playerHand.length < 12)
{
// put card into hand
this.$set(this.gameState, 'playerHand', [...this.gameState.playerHand, card])
// this.gameState.playerHand.push(card)
}
// otherwise discard card
},
retrieveDeck() {
let array = []
for (let i = 0; i < 20; i++)
{
array.push(this.src + "?text=card"+i)
}
this.$set(this.gameState, 'playerDeck', array)
},
},
mounted() {
this.retrieveDeck()
for (let i = 0; i < 5; i++)
{
this.addToHand(1)
}
},
export default {
name: 'PlayerCards',
props: ["gameState", "hand"],
data() {
return {
}
},
computed: {
rows() {
let cards = this.gameState.playerHand
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
}
}
}
하지만 행의 내용이 비어 있습니다.
업데이트 (업데이트 바이올린) :
문제는 컴퓨팅 함께
https://jsfiddle.net/f3w69rr6/1/
흠, 나는 당신이 소품의 유형을 고쳐야한다고 생각합니다. 아무 것도 영향을 미치지 만 시도해 봐야할지 모르겠다. https://vuejs.org/v2/guide/components.html#Prop-Validation – pirs
'this.gameState'를 위해 마운트 된 값을 얻으시겠습니까? 하위 구성 요소에서? – C2486
@ user2486 그래서 브라우저에서'console.log (this.gameState)'를 실행하면 내용이 있음을 보여줄 것입니다, 그러나'Object.assign ({}, this.gameState)'를 다른 것으로 실행하면 로그를 남기면 초기화 될 때 예상대로 비어있게됩니다. 문제는 그것이 내 피들에서 잘 작동하는 동안 내 애플 리케이션에 반응이 없다는 것입니다. 필요한 경우 더 많은 코드를 게시 할 수 있습니다. 어떤 이유로 든 –