Nuxtjs3+ElementPlus 提示:[IdInjection] Looks like you are using server rendering, you must provide a id...

技术 · 17 天前 · 访问: 81 次

Snipaste_2024-11-05_15-03-29.png

根据提示可以看出需要提供一个id。

文档:https://element-plus.org/zh-CN/guide/ssr.html#%E6%8F%90%E4%BE%9B%E4%B8%80%E4%B8%AAid

代码:

// plugins/ElementPlus.ts
import { defineNuxtPlugin } from '#app'
import ElementPlus, { ID_INJECTION_KEY } from 'element-plus'
import 'element-plus/dist/index.css'

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.vueApp.provide(ID_INJECTION_KEY, { prefix: 1024, current: 0 })
  nuxtApp.vueApp.use(ElementPlus)
})
前端 报错处理 报错问题处理 element-plus nuxt.js
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
Theme Jasmine by Kent Liao