如何在SFC中即时编译模板?

时间:2020-04-07 20:31:07

标签: vue.js

上下文:我要呈现从数据库下载的模板。这些模板可以包含自定义vue组件。

我尝试使用Vue.compile,但无法识别导入的sfc组件:

// App.vue

import HelloWorld from "./components/HelloWorld";
import Vue from "vue";

export default {
  name: "App",
  functional: true,
  components: {
    HelloWorld
  },
  render(h) {
    // works fine
    // return h(Vue.compile(`<div>test</div>`));

    // doesn't work
    return h(Vue.compile(`<HelloWorld />`));
  }
};

这将返回错误:

Unknown custom element: <HelloWorld>

这是一个沙箱: https://codesandbox.io/s/vue-compile-3x590?file=/src/App.vue

0 个答案:

没有答案