场景:使用vuepress
编写文档,想顺便加上一个编辑运行代码
的功能,比如编写一段.vue
格式的文本,然后运行渲染界面。然而碰上了一个问题
[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
关键代码如下
// 该代码导致报错,因为无法使用template,如果使用render的话倒是可以成功渲染
new Vue({
mixins: [script], // 上图代码中script标签中export default的内容
el: '#' + codePreviewID,
template: template // 上图代码中template标签的内容
});
那么问题来了,如何将template转化成render?有插件或方法可以直接用么?
已经想到了骚主意,改编译环境,直接跳过问题