在 Vue 模板中,我在 pug 语法中有这个 html
<template lang="pug">
div
- var cards = [{ title: 'Mountain View' },{ title: 'Mountain View' }]
mixin card(title, copy, button)
.card
.content
h2.title= title
p.copy= copy
button.btn= button
main.page-content
each card in cards
+card(card.title)
</template>
在脚本标签中,我使用 axios 从 json 文件中获取数据。
<script>
import axios from "axios";
export default {
data() {
return {
players: [],
loading: true,
errored: false
};
},
methods: {
fetchData() {
axios
.get("data.json")
.then(response => this.players = response.data)
.catch(error => {
console.log(error);
this.errored = true;
})
.finally(() => (this.loading = false));
}
},
mounted() {
this.fetchData();
}
}
</script>
我的问题是如何从players
财产中获取数据cards
?