【问题标题】:Vue3: How to use Vue.compile in Vue3Vue3:如何在 Vue3 中使用 Vue.compile
【发布时间】:2021-10-29 01:06:44
【问题描述】:

问题:如何在 Vue3 运行时使用 Vue.$compile 编译函数? 我在Vue2中使用该功能。例如:

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

【问题讨论】:

  • import {compile,createApp} from vue; let component = createApp({render:compile('&lt;custom-component /&gt;')});
  • @MichalLevý 但我如何创建具有属性 $el 的 vNode(如 this.$el)并将其动态附加到文档
  • 嗯,这是一个非常不同的问题。我建议您使用当前 Vue 2 解决方案的详细示例打开一个新示例.....
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: vuejs3


【解决方案1】:
import {compile} from "vue"

compile('<custom-component />')

就是这样,几乎一样!

那你就可以了

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-06
    • 2023-01-24
    • 1970-01-01
    • 2021-04-03
    • 2021-05-28
    • 1970-01-01
    • 2022-12-22
    • 2021-03-07
    相关资源
    最近更新 更多