Vue-实现this。$ options.staticRenderFns

时间:2019-01-20 16:52:24

标签: vue.js vuejs2 vue-component

我正在尝试使用自定义渲染功能实现Vue组件。 一旦我的模板嵌套了HTML元素,就会出现此错误:

TypeError: this.$options.staticRenderFns is undefined

如何实现 staticRenderFns

代码:

<!doctype html>
<html>
<head>
    <meta charset="utf-8" /> 
    <script src="https://unpkg.com/vue"></script>
</head>
<body>
    <div id="app">
        <comp temp="temp1"></comp>
    </div>
    <script>
        var myTemplates = new Array();
        myTemplates['temp1'] = Vue.compile("<div><div>This template will come from an AJAX source</div></div>").render; 

        var Comp = {
          props: ["temp"], 
          data() {
            return {
                renderFunc: myTemplates[ this.$props.temp ],
            }
          },
          render(h) {
            return this.renderFunc()
          }
        };

        new Vue({
          el: "#app",
          data: { },
          components: { Comp }
        });
    </script>
</body>
</html>

0 个答案:

没有答案