如何在 Vue 3 中使用 Vue.compile?

Fly*_*Sky 7 vue.js vuejs3

如何Vue.$compile在 Vue 3 运行时中使用编译函数?我在Vue 2中使用该函数。例如:

Vue.compile('<custom-component />');
Run Code Online (Sandbox Code Playgroud)

Jav*_*ict 4

import {compile} from "vue"

compile('<custom-component />')
Run Code Online (Sandbox Code Playgroud)

仅此而已,几乎一样!

然后你可以做

render() {
  return h({render: compile('<custom-component />')})
}
Run Code Online (Sandbox Code Playgroud)

一旦您无法指定模板的导入,如果它包含自定义组件,则它们必须事先在启动时使用 app.component 函数注册:vuejs.org/api/application.html#app-component