简体   繁体   English

Ant Design Vue:模态组件不适用于合成 API

[英]Ant Design Vue: Modal Component will not work with the Composition API

I'm using Vue3 with Ant Design Vue and would like create a 'Modal' component that I can reuse throughout the app.我将 Vue3 与Ant Design Vue一起使用,并希望创建一个“模态”组件,我可以在整个应用程序中重复使用它。

Something very simple like so:像这样非常简单的东西:

<template>
    <a-button type="primary" @click="showModal">Open</a-button>
    <a-modal v-model="visible" wrap-class-name="full-modal-to-xl">
        <p>Some contents...</p>
        <p>Some contents...</p>
        <p>Some contents...</p>
    </a-modal>
</template>

<script lang="ts">
import { ref, defineComponent } from "vue";

export default defineComponent({
    setup() {
        const visible = ref(false);

        const showModal = () => {
            visible.value = true;
        };
        return { visible, showModal };
    },
});
</script>

But it simply will not work...(no console log, or error).但它根本行不通......(没有控制台日志或错误)。

It does seem to work when you pass visible as a prop, but I really do not want to do that.当您将visible作为道具传递时,它似乎确实有效,但我真的不想那样做。 This should work just as well...这应该也能工作......

What am I missing?我错过了什么?

EDIT: Solution (but not really a solution) Using the Composition API is not feasible with Ant it seems.编辑:解决方案(但不是真正的解决方案)使用组合 API似乎与 Ant 不可行。

The modal's v-model needs to be on its visible prop:模态的v-model需要在它的visible属性上:

<a-modal v-model:visible="visible">
                    👆

demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM