0
我試圖在我的vue組件中顯示數據,並且我有一個擁有對象的數組。如果我嘗試使用Vue JS無法顯示數據
<div class="bar">
{{playersStats[0]}}
</div>
它顯示
{ "GP": 13, "GS": 6, "MPG": 20.74, "PPG": 12.85, "FGM": 4.46, "FGA": 9.77, "FGP": 0.46 }
但如果我嘗試使用
<div class="bar">
<span v-if="playersStats[0]">{{playersStats[0].GS}}</span>
</div>
EDITED的Javascript:
export default {
data: function(){
return {
showPlayersSelection: true,
selectedPlayers: [],
playersStats: []
}
},
methods: {
selectPlayers(player) {
if(this.selectedPlayers.length < 2){
this.selectedPlayers.push(player);
if(this.selectedPlayers.length == 2){
this.getPlayerStats(this.selectedPlayers[0][0], this.selectedPlayers[1][0]);
this.showPlayersSelection = false;
}
}
return false;
},
getPlayerStats(player1, player2) {
let self = this;
axios.get(config.API.URL + config.API.STATS, {
params: {
'player1Id': player1,
'player2Id': player2
}
})
.then((response) => {
if(response.status == 200 && typeof(response.data) == 'object'){
self.playersStats = [];
self.playersStats.push(response.data[0][0]);
self.playersStats.push(response.data[1][0]);
}
});
},
}
}
它顯示甚至沒有在DOM中。我怎樣才能顯示數據?
數據來自哪裏?也許你需要返回response.json()?你可以分享這個問題的小提琴嗎? – Nora
如果你做了'
工作正常[在小提琴](https://jsfiddle.net/qtzkpa8j/) –