vue.jsvuejs3

How to use Vue.compile in Vue 3?


How can I use Vue.$compile to compile function in Vue 3 runtime? I use the function in Vue 2. For example:

Vue.compile('<custom-component />');

Solution

  • import {compile} from "vue"
    
    compile('<custom-component />')
    

    that's all, almost the same!

    Then you can do

    render() {
      return h({render: compile('<custom-component />')})
    }
    

    As soon as you can't specify imports for the template, if it contains custom components they must have been registered previously with the app.component function at startup: vuejs.org/api/application.html#app-component