<template> <div> <v-expansion-panel> <v-expansion-panel-content v-model="item.active" v-for="item in items" :key="item.title" :prepend-icon="item.action" :ddd="item.ddd" no-action> <div slot="header">{{ item.title }}</div> <v-card v-for="subItem in item.items" :key="subItem.title"> <a href="#" @click.stop="dialog = true"> <v-card-text >{{ subItem.title }}-{{ subItem.ddd }} </v-card-text></a> </v-card> </v-expansion-panel-content> </v-expansion-panel> <v-dialog v-model="dialog" max-width="500px"> <v-card> <v-card-title class="headline">Use Google's location service?</v-card-title> <v-card-text>{{subItem.ddd}}</v-card-text>/ <v-card-actions> <v-spacer></v-spacer> <v-btn color="green darken-1" flat="flat" @click.native="dialog = false">Disagree</v-btn> <v-btn color="green darken-1" flat="flat" @click.native="dialog = false">Agree</v-btn> </v-card-actions> </v-card> </v-dialog> </div> </template> <script> export default { data () { return { dialog: false, items: [ { action: 'local_activity', title: 'Attractions', items: [ { title: 'List Item' } ] }, { action: 'restaurant', title: 'Dining', items: [ { title: 'Breakfast & brunch', ddd: '1234' }, { title: 'New American', ddd: '5678' }, { title: 'Sushi', ddd: '91011' } ] }, { action: 'school', title: 'Education', items: [ { title: 'List Item' } ] }, { action: 'directions_run', title: 'Family', items: [ { title: 'List Item' } ] }, { action: 'healing', title: 'Health', items: [ { title: 'List Item' } ] }, { action: 'content_cut', title: 'Office', items: [ { title: 'List Item' } ] }, { action: 'local_offer', title: 'Promotions', items: [ { title: 'List Item' } ] } ] } } } </script> |
1 answer
Because the v-dialog does not have access to the subItem . Since the v-dialog is outside the v-for loop. To fix this, you can do this:
@click.stop="dialog = true"change to@click.stop="changeState(subItem)"In the
export defaultadd the following code:methods: { changeState(subItem) { this.obj = subItem } }In
data()add this:obj: nullIn your
v-dialoginstead of{{ subItem.ddd }}put{{ obj.ddd }}
Also, not all your items have ddd
PS Questions about vue.js best written in stackoverflow English. Since there are not very many Russian vue.js developers
- <a href="#" @click.stop="changeState(subItem)"> <script> export default {computed: {changeState (subItem) {this.obj = subItem}}, data () {obj: null return { dialog: false, items: [{action: 'local_activity', title: 'Attractions', items: [{title: 'List Item', ddd: '1234'}] - Andrey
|
obj: nullputobj: {}- Yernar