siobeh
siobeh

Reputation: 31

v-dialog not showing upon clicking the v-btn inside v-data-tables

I'm new to vuejs and I'm using vuetify.I just want to show a dialog upon clicking the button inside the v-data-table. This is what I have done so far.

https://codepen.io/iskaryote1/pen/GbYjZJ?&editable=true&editors=101

v-dialog

<v-dialog v-model="dialog" persistent max-width="290">
          <template v-slot:activator="{ on }">
            <v-btn color="primary" dark v-on="on">Open Dialog</v-btn>
          </template>
          <v-card>
            <v-card-title class="headline">Use Google's location service?</v-card-title>
              <v-card-text>Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.</v-card-text>
            <v-card-actions>
              <v-spacer></v-spacer>
              <v-btn color="green darken-1" flat @click="dialog = false">Disagree</v-btn>
              <v-btn color="green darken-1" flat @click="dialog = false">Agree</v-btn>
            </v-card-actions>
          </v-card>
        </v-dialog>

everytime I click the button, my browser hangs and the console log says too much recursion

Thanks in advance.

Upvotes: 0

Views: 7709

Answers (2)

Sovalina
Sovalina

Reputation: 5609

Just put the dialog modal outside the table and open it programmatically with a simple button:

<div id="app">
  <v-app id="inspire">
    <v-data-table
      :headers="headers"
      :items="desserts"
      class="elevation-1">
      <template v-slot:items="props">
        <td>{{ props.item.name }}</td>
        <td class="text-xs-right">{{ props.item.calories }}</td>
        <td class="text-xs-right">{{ props.item.fat }}</td>
        <td class="text-xs-right">{{ props.item.carbs }}</td>
        <td class="text-xs-right">{{ props.item.protein }}</td>
        <td class="text-xs-right">{{ props.item.iron }}</td>
        <td>
          <v-btn color="primary" dark @click="dialog = true">Open Dialog</v-btn>
        </td>
      </template>
    </v-data-table>

    <v-dialog v-model="dialog" persistent max-width="290">
      <v-card>
        <v-card-title class="headline">Use Google's location service?</v-card-title>
        <v-card-text>Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.</v-card-text>
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn color="green darken-1" flat @click="dialog = false">Disagree</v-btn>
          <v-btn color="green darken-1" flat @click="dialog = false">Agree</v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>    
  </v-app>
</div>

Upvotes: 3

Samuel-Zacharie Faure
Samuel-Zacharie Faure

Reputation: 1152

The recursion is vuetify trying to open a slot in a slot in a slot... Looks like your template slot itself is opening itself every time it opens itself.

I'd advise you to read this answer that gives detailed explanations on the use of v-slot:activator.

Upvotes: 0

Related Questions