【发布时间】:2018-01-23 22:46:21
【问题描述】:
我目前正在使用 Vue JS,但我没有使用任何路由器。我没有使用独立构建,而是希望使用 webpack 实现并将其与 .vue 扩展名一起使用。寻找使用变量呈现 Vue 模板的更好方法。例如:
// App.Vue
var Loading = {
template: `<div>Loading...</div>`
}
// main.js
var currentView = Loading;
new Vue({
el: "#app",
render(h) {
return h(currentView);
}
});
上面的例子完全没有问题。想了解是否有更好的处理方法。
假设 currentView 是否包含类似
的字符串currentView = "Loading"
render(h) {
return h(eval(currentView)); // works
return h([currentView]); // template not found or mount error
}
我们如何在模板传递给渲染函数之前将值替换为模板?
提前致谢。
【问题讨论】:
标签: javascript vue.js vuejs2 vue-component