vue.js - Vue - 实现 this.$options.staticRenderFns
问题描述
我正在尝试使用自定义渲染功能实现 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>
解决方案
推荐阅读
- python - python多态性重载故障
- sql - 基于两列日期时间条件的 SQL SUM
- word2vec - 有没有办法通过 word2vec 嵌入计算形容词相对于普通名词之间的语义距离?
- selenium - Robot Framework 在 RDP 客户端上执行测试
- git - git 存储库可以指定所需的最低 git 版本吗?
- javascript - 有什么办法可以在浏览器上从我的网站打开word文档
- arrays - Laravel where() 返回对象而不是数组
- random - 是否可以使用任意长度的向量作为种子来创建 RNG,而无需自己创建整个 RNG 实现?
- flutter - Flutter - 找不到名为“-”的命令
- html - 将响应式网页设计与大量背景图像相结合