Created
November 25, 2019 17:18
-
-
Save adrianjost/3790b9d79321b8a9f66ae3900d2d1029 to your computer and use it in GitHub Desktop.
RenderHtml Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Cool way to render Vue components from HTML Strings | |
// https://medium.com/haiiro-io/compile-markdown-as-vue-template-on-nuxt-js-1c606c15731c | |
import VueWithCompiler from "vue/dist/vue.esm"; | |
export default { | |
props: { | |
html: { | |
type: String, | |
default: "", | |
}, | |
}, | |
data() { | |
return { templateRender: undefined }; | |
}, | |
watch: { | |
html(to) { | |
this.updateRender(); | |
}, | |
}, | |
created() { | |
this.updateRender(); | |
}, | |
methods: { | |
updateRender() { | |
const compiled = VueWithCompiler.compile(this.html); | |
this.templateRender = compiled.render; | |
this.$options.staticRenderFns = []; | |
for (const staticRenderFunction of compiled.staticRenderFns) { | |
this.$options.staticRenderFns.push(staticRenderFunction); | |
} | |
}, | |
}, | |
render() { | |
return this.templateRender(); | |
}, | |
}; | |
</script> |
@ponceleon I guess it's because you are using Vue 3 (guessed because of vue@next
) wich has a lot of API changes. I imagine the method I used doesn't work with Vue 3 anymore.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello friend, you will have any idea why I get this error.
I am running the code you shared on medium.