Skip to content

(Q&A and Idea) How do i set html default value in Vue dom? #985

Closed Answered by Saul-Mirone
Nemure231 asked this question in Q&A
Discussion options

You must be logged in to vote

The dom hasn't been rendered for vue in your case, move the markdown variable into onMounted:

<script setup lang="ts">
import { Milkdown, useEditor } from '@milkdown/vue';
import { defaultValueCtx, Editor, rootCtx } from '@milkdown/core';
import { nord } from '@milkdown/theme-nord'
import { commonmark } from '@milkdown/preset-commonmark'

useEditor((root) => {
  return Editor.make()
    .config(nord)
    .config((ctx) => {
      ctx.set(rootCtx, root)
      ctx.set(defaultValueCtx, {
        type: 'html',
        dom: document.querySelector('#pre'),
      })
    })
    .use(commonmark)
})
</script>

<template>
  <div id="pre">
    <h1>Milkdown Vue Commonmark</h1>
  </div>
  <Milkdown />
</t…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Nemure231
Comment options

Answer selected by Nemure231
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants