【问题标题】:Dialogs are not shown in vuetify 3vuetify 3中未显示对话框
【发布时间】:2021-09-12 13:22:21
【问题描述】:

我正在尝试将 vuetify 3.alpha 与 vue 3 一起使用。这些是我的文件:

Temp.vue(取自 vuetify example

<template>
  <div class="text-center">
    <v-dialog
      v-model="dialog"
      width="500"
    >
      <template v-slot:activator="{ on, attrs }">
        <v-btn
          color="red lighten-2"
          dark
          v-bind="attrs"
          v-on="on"
        >
          Click Me
        </v-btn>
      </template>

      <v-card>
        <v-card-title class="text-h5 grey lighten-2">
          Privacy Policy
        </v-card-title>

        <v-card-text>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        </v-card-text>

        <v-divider></v-divider>

        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn
            color="primary"
            text
            @click="dialog = false"
          >
            I accept
          </v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        dialog: false,
      }
    },
  }
</script>

App.vue

<template>
  <v-app>
    <v-main>
        <Temp/>
    </v-main>
  </v-app>
</template>


<script lang="ts">
import { defineAsyncComponent, defineComponent, reactive, ref, Ref, watch, createApp, onMounted} from 'vue'
import Temp from './Temp.vue'

export default defineComponent({
    name: 'App',

    components: {
        Temp
    },

    setup () {

    },
   data () {
      return {

      }
    },
})

</script>

这就是我得到的:

问题是当我点击这个按钮时没有显示对话框。这是我在 alpha 版本中的错误或错误吗?

【问题讨论】:

    标签: typescript vue.js vuetify.js vuejs3 vuetifyjs3


    【解决方案1】:

    即使官方 vuetify 文档中使用激活器插槽的示例也无法正常工作。

    您可以将@click.stop="dialog = true" 添加到打开对话框的按钮中,然后从中删除v-on="on"

    【讨论】:

      【解决方案2】:

      根据官方source code 你可以这样做:

            <template v-slot:activator="{isActive,props}">
              <v-btn
                color="red lighten-2"
                dark   @click="props.onClick[0]"
              >
                Click Me
              </v-btn>
            </template>
      

      DEMO

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-11-10
        • 2013-06-28
        • 2016-05-30
        • 2017-02-05
        • 2017-07-03
        • 1970-01-01
        相关资源
        最近更新 更多