view-design / ViewUIPlus

An enterprise-level UI component library and front-end solution based on Vue.js 3
https://www.iviewui.com
Other
384 stars 134 forks source link

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

Open cy08 opened 7 months ago

cy08 commented 7 months ago

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)

请问大佬这需要怎么解决

h3clikejava commented 6 months ago

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