view-design/ViewUIPlus

Vue3 加载报错 TypeError: Cannot read properties of undefined (reading 'add') 版本: "view-ui-plus": "^1.3.16",

Opened this issue · 1 comments

cy08 commented

main.js
`
import { createApp } from 'vue'
import App from '@/App.vue'
import ViewUIPlus from 'view-ui-plus'

const app = createApp(App);
app.provide('Message', ViewUIPlus.Message);
app.mount('#app');
`

index.js
`
import { ref, inject, reactive, watch, computed, onMounted } from "vue";
const Message = inject("Message");

nMounted(async () => {

Message.loading({
content: "加载中...",
duration: 0,
});
})
`

出现错误

view-ui-plus.js?v=1bd0da6a:10103 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'add') at Object.notice (view-ui-plus.js?v=1bd0da6a:10103:13) at a0 (view-ui-plus.js?v=1bd0da6a:10123:18) at Object.message (view-ui-plus.js?v=1bd0da6a:10146:62) at Object.error (view-ui-plus.js?v=1bd0da6a:10142:21) at onSearch (index.vue:680:13) at index.vue:401:5 at chunk-XGACGZPK.js?v=6e19c5a1:7673:92 at callWithErrorHandling (chunk-XGACGZPK.js?v=6e19c5a1:1722:18) at callWithAsyncErrorHandling (chunk-XGACGZPK.js?v=6e19c5a1:1730:17) at hook.__weh.hook.__weh (chunk-XGACGZPK.js?v=6e19c5a1:3467:19)

请问大佬这需要怎么解决

在onMounted里面不能用Message,估计是控件还没初始化。放到后面的逻辑里就可以。