【发布时间】:2020-08-05 07:38:50
【问题描述】:
我是 Vue 的新手,我正在尝试遍历一个数组。不完全知道我做错了什么,但列表没有显示在 HTML 上。下面是代码: 这是一个通过路由器视图呈现的索引文件。
<template>
<div class="index container">
<div class="card" v-for="tournament in tournaments" :key="tournament.id">
<div class="card-content">
<h2 class="indigo-text">{{tournament.title}}</h2>
<ul class="tournaments">
<li v-for="(score,index) in tournamnet.scores" :key="index"></li>
<span class="chip">{{score}}</span>
</ul>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'index',
data () {
return {
tournaments:[
{title:'Muthaiga golf Tournament',slug: 'muthaiga-golf-tournament',scores:['Round 1', 'Round 2', 'Round 3'],id:'1'},
{title:'Wilson Churchhill',slug: 'Wilson Churchhill',scores:['Round 1', 'Round 2', 'Round 3'],id:'2'},
]
}
},
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
</style>
这里是路由器视图 index.js
import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'index',
component: index
}
]
})
这里是 app.vue
<template>
<div id="app">
<navbar />
<router-view/>
</div>
</template>
<script>
import navbar from '@/components/navbar'
export default {
name: 'App',
components:{
navbar
}
}
</script>
我们将不胜感激。
【问题讨论】:
-
你看到了什么?你看到你的
navbar了吗?<div class="index container">呢?究竟是什么没有按预期工作? -
这能回答你的问题吗? Correct way to handle v-if with v-for in Vue
-
我可以看到我的导航栏,但我看不到你确定这不是因为你写的错字
tournamnet.scores而不是tournament.scores?
标签: vue.js