Closed vincerubinetti closed 11 months ago
Hello, thanks for your Issue. I will have a look at it soon. I think I have to release a new major version which only works with vue 3.
@p-kuen Take a look to vue-demi, you should be able to keep same syntax and use the component on both vue2 and vue3
Here is a sample of the component that work with vue 3
<script lang="ts">
import type { PropType } from 'vue'
import { defineComponent, computed, h } from 'vue'
import MarkdownIt, { Options as MarkdownItOptions } from 'markdown-it'
export default defineComponent({
name: 'VueMarkdown',
props: {
source: {
type: String,
required: true,
},
options: {
type: Object as PropType<MarkdownItOptions>,
default: () => ({}),
required: false,
},
},
setup(props, { attrs }) {
const md = new MarkdownIt(props.options)
const content = computed(() => {
const src = props.source
return md?.render(src)
})
return () =>
h('div', {
...attrs,
innerHTML: content.value,
})
},
})
</script>
Here is a sample of the component that work with vue 3
<script lang="ts"> import type { PropType } from 'vue' import { defineComponent, computed, h } from 'vue' import MarkdownIt, { Options as MarkdownItOptions } from 'markdown-it' export default defineComponent({ name: 'VueMarkdown', props: { source: { type: String, required: true, }, options: { type: Object as PropType<MarkdownItOptions>, default: () => ({}), required: false, }, }, setup(props, { attrs }) { const md = new MarkdownIt(props.options) const content = computed(() => { const src = props.source return md?.render(src) }) return () => h('div', { ...attrs, innerHTML: content.value, }) }, }) </script>
Works for me, thanks!
Since 2.0.0 this package is compatible with vue 3, since 2.1.1 this package also uses the composition api. Therefore this issue will be closed.
Thanks for this library, but it seems like it doesn't support Vue 3 with Typescript (correct me if I'm wrong).
Trying a basic example:
I get the following error on the
components: { VueMarkdown }
line:I'm not an expert in Typescript or in the differences between Vue 2 and 3, but it seems like the types that Vue is expecting for
components
might have changed.