【问题标题】:v-dialog not showing upon clicking the v-btn inside v-data-tables单击 v-data-tables 中的 v-btn 时未显示 v-dialog
【发布时间】:2019-11-17 06:08:02
【问题描述】:

我是 vuejs 的新手,我正在使用 vuetify。我只想在单击 v-data-table 内的按钮时显示一个对话框。这是我到目前为止所做的。

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>

每次单击按钮时,我的浏览器都会挂起,并且控制台日志显示 递归过多

提前致谢。

【问题讨论】:

    标签: vue.js vuetify.js


    【解决方案1】:

    只需将对话框模式放在表格之外,然后用一个简单的按钮以编程方式打开它:

    <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>
    

    【讨论】:

    • 它工作,但你知道为什么我的另一个不工作吗?
    【解决方案2】:

    递归是 vuetify 试图在插槽中的插槽中打开一个插槽...看起来您的模板插槽本身每次打开时都会自行打开。

    我建议您阅读this answer,其中详细解释了v-slot:activator 的使用。

    【讨论】:

    猜你喜欢
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 2020-12-11
    • 2021-01-24
    • 2019-11-05
    • 2021-11-22
    • 2019-08-20
    相关资源
    最近更新 更多