You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are two places where “custom elements” matter:
261
+
262
+
-**Vue template compiler (compile-time)**: controls whether Vue treats `<my-element>` as a component or a custom element.
263
+
-**MDC renderer (runtime)**: controls whether MDC tries to resolve a tag as a Vue component when rendering markdown.
264
+
265
+
### Vue (compile-time)
266
+
When using custom elements in Vue templates, configure Vue to recognize them by adding `vue.compilerOptions.isCustomElement` in your `nuxt.config.ts`.
267
+
268
+
```ts [nuxt.config.ts]
269
+
exportdefaultdefineNuxtConfig({
270
+
vue: {
271
+
compilerOptions: {
272
+
isCustomElement: (tag) =>tag.startsWith('mjx')
273
+
}
274
+
}
275
+
})
276
+
```
277
+
278
+
### MDC (runtime)
279
+
MDC does not use Vue’s template compiler options when rendering markdown. To tell MDC which tags should be treated as custom elements (and therefore **not** resolved as Vue components), add them to `mdc.components.customElements`.
280
+
281
+
```ts [nuxt.config.ts]
282
+
exportdefaultdefineNuxtConfig({
283
+
mdc: {
284
+
components: {
285
+
customElements: ['mjx-container']
286
+
}
287
+
}
288
+
})
289
+
```
290
+
291
+
When `mdc.components.customElements` is provided and `vue.compilerOptions.isCustomElement` is not already set, MDC will also configure Vue to treat those same tags as custom elements.
292
+
293
+
Now you can use custom elements as below.
294
+
295
+
```html [custom-element.vue]
296
+
<scriptsetup>
297
+
constmdc=`
298
+
# Custom elements can now be used
299
+
300
+
::mjx-container
301
+
This is rendered as a custom element
302
+
::
303
+
`
304
+
</script>
305
+
306
+
<style>
307
+
my-element {
308
+
color: red;
309
+
}
310
+
</style>
311
+
312
+
<template>
313
+
<div>
314
+
<MDC:value="mdc" />
315
+
<my-element>Another custom element</my-element>
316
+
</div>
317
+
</template>
318
+
```
319
+
258
320
## Contributing
259
321
260
322
You can contribute to this module online with CodeSandbox:
0 commit comments