Dan*_*ina 2 javascript vue.js vue-component vuetify.js
我试图根据我有多少个答案来迭代 v-divider,以便每个答案都有一个分隔符 (4)。从官方文档的一个例子中得到提示,我正在尝试类似的事情,但我无法理解,有人可以向我解释我错在哪里?

这是代码:
<template>
<div class="dark2">
<v-card max-width="600" class="mx-auto">
<v-toolbar extended class="mt-10" color="light-blue" dark>
<v-toolbar-title class="flex text-center">
<h2 class="text-center mt-10">Quiz Dark 2</h2>
</v-toolbar-title>
</v-toolbar>
<v-progress-linear :value="progress"></v-progress-linear>
<v-list subheader two-line v-for="(element, index) in questions.slice(a,b)" :key="index" v-show="quiz">
<h1 class="text-center my-4">Domanda {{ b }}/{{ questions.length }}</h1>
<v-list-item class="d-flex justify-center text-center">{{ element.question }}</v-list-item>
<v-divider class="mt-10"></v-divider>
<v-list-item-group active-class="pink--text">
<v-list-item class="d-flex justify-center my-2" v-for="(item, index) in element.suggestions" :key="index">
{{ item.suggestion }}
</v-list-item>
<v-divider v-if="index < questions.length - 1"
:key="index"></v-divider>
</v-list-item-group>
</v-list>
</v-card>
</div>
</template>
<script>
export default {
data() {
return {
questions: [
{
question: 'Cosa lascia Micheal kanhnwald a suo figlio Jonas prima di impiccarsi?',
suggestions: [
{suggestion: 'Un libro'},
{suggestion: 'Una lettera'},
{suggestion: 'Una torcia futuristica'},
{suggestion: 'Un contatore Geiger'}
]
}
],
a: 0,
b: 1,
select: false,
score: 0,
quiz: true,
score_show: false,
next: false,
progress: 0
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
正如您在 Vuetify 官方文档Lists Component / Action stack提供的示例中看到的,您template的标签内应该有一个标签v-list-item-group。像这样的东西:
<v-list-item-group active-class="pink--text">
<template v-for="(item, index) in element.suggestions">
<v-list-item class="d-flex justify-center my-2" :key="index">
{{ item.suggestion }}
</v-list-item>
<v-divider
v-if="index < element.suggestions.length - 1"
:key="`${index}-divider`"
></v-divider>
</template>
</v-list-item-group>
Run Code Online (Sandbox Code Playgroud)
唯一的区别是拥有templateinside v-list-item-group,然后添加v-divider到v-list-itemcustom 内部template。
希望它有所帮助,编码愉快。
| 归档时间: |
|
| 查看次数: |
6819 次 |
| 最近记录: |