Uncaught (in promise) TypeError: Cannot read properties of null (reading ‘parentNode’)

runtime-core.esm-bundler.js:38 [Vue warn]: Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/core
在这里插入图片描述
需要定义一个ID_INJECTION_KEY给后续组件使用,引用element-plus修改如下

import { defineNuxtPlugin } from '#app'

import ElementPlus from 'element-plus'
import { ID_INJECTION_KEY } from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from 'element-plus/es/locale/lang/zh-cn'

export default defineNuxtPlugin(nuxtApp => {
  if (process.client) {
    const app = nuxtApp.vueApp
    app
      .provide(ID_INJECTION_KEY, {
        prefix: Math.floor(Math.random() * 10000),
        current: 0
      })
      .use(ElementPlus, {
        size: 'small',
        locale: zhCn
      })

    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      if (key === 'Link') {
        continue
      }
      app.component(key, component)
    }
  }
})```

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐