出现的问题

在引入earth-ui到现有的vue项目中,出现

1
[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选项;

如何解决

  1. 使用运行时版本
    本次项目主要使用vue-cli3创建,因此首先在vue.config.js文件中配置
    1
    2
    3
    4
    5
    module.exports = {
    ...
    runtimeCompiler: true
    ...
    }
    然后确认main.js里使用render渲染:
    1
    2
    3
    4
    new Vue({
    router,
    render: h => h(App),
    }).$mount('#app')
  2. 使用完整版本
    1
    2
    3
    4
    5
    6
    7
    8
    module.exports = {
    // ...
    resolve: {
    alias: {
    'vue$': 'vue/dist/vue.esm.js' // 用 webpack 1 时需用 'vue/dist/vue.common.js'
    }
    }
    }

    参考文章

  3. vue.js官网 https://cn.vuejs.org/v2/guide/
  4. Fix “[Vue warn]: You are using the runtime-only build of Vue”

评论