Skip to content

App包裹组件 在 pinia 全局场景 中 App.useApp() 返回的 message notification modal 等为空 #7931

@puzzle9

Description

@puzzle9
  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

4.2.6

Environment

vue 3.5.12

Reproduction link

Edit on CodeSandbox

Steps to reproduce

app.vue

<template>
app
<br />
<a-config-provider :locale="zhCN">
<a-app>
<router-view />
</a-app>
</a-config-provider>
</template>

<script setup>
import zhCN from "ant-design-vue/es/locale/zh_CN";
</script>

index.vue

<template>
index

<br />

<a-button @click="addd">点我看提示</a-button>
</template>

<script setup>
import { useGlobalStore } from "./pinia";
const global = useGlobalStore();

console.log(global);

const addd = () => {
console.log(global.message);
console.log(global.message.info("infoa"));
};
</script>

pinia

import { App } from "ant-design-vue";
import { defineStore } from "pinia";
import { ref } from "vue";

export const useGlobalStore = defineStore("global", () => {
const message = ref();
const notification = ref();
const modal = ref();
(() => {
const staticFunction = App.useApp();
message.value = staticFunction.message;
modal.value = staticFunction.modal;
notification.value = staticFunction.notification;
})();

return { message, notification, modal };
});

What is expected?

可以弹出 message 提示

What is actually happening?

global.message.info is not a function

index.vue

14 |
15 | const addd = () => {
16 |   console.log(global.message);
> 17 |   console.log(global.message.info("infoa"));
|                             ^
18 | };
19 | </script>
20 |

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions