【发布时间】:2018-05-18 09:55:50
【问题描述】:
将 Vue.compile 用于异步 HTML 似乎具有两个元素深度的最大复杂性。任何更高的值都会在渲染时抛出 Error in render: "TypeError: Cannot read property '0' of undefined"。
所以<section><p>hello</p><section> 工作正常,但<section><p>hello <em>there</em></p><section> 失败。
下面的代码示例和a fiddle。 (由 setTimeout 模拟异步)
new Vue({
el: '#app',
data: {
msg: 'simple template works',
template: Vue.compile('<p>{{msg}}</p>').render
},
render(createElement) {
return this.template();
},
mounted() {
// below fails
setTimeout(()=>{
this.template = Vue.compile('<div><p>{{msg}}</p><p>Nesting more than three tags deep <em>fails</em>?</p></div>').render;
}, 1000);
// below renders fine
setTimeout(()=>{
this.template = Vue.compile('<div><p>{{msg}}</p><p>Nesting more than three tags deep fails?</p></div>').render;
}, 2000);
}
})
谁能告诉这里发生了什么?是否应该以不同方式编译/呈现“复杂”模板?
【问题讨论】:
标签: javascript vue.js compilation runtime