vue如何将template转化成render?

场景:使用vuepress编写文档,想顺便加上一个编辑运行代码的功能,比如编写一段.vue格式的文本,然后运行渲染界面。然而碰上了一个问题

clipboard.png

[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?有插件或方法可以直接用么?

阅读 5.6k
1 个回答

已经想到了骚主意,改编译环境,直接跳过问题

// import Vue from 'vue';
import Vue from 'vue/dist/vue.js';
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题