关于vue编译版本引入的问题的解决

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

关于vue编译版本引入的问题的解决

飘飘然   2020-05-16 我要评论

下班过目遇到一个错误

[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.

根据错误提示说明,和搜索之后得出结论:是项目引入的vue编译版本不对

解决方案1

build/webpack.base.conf.js 并设置vue的alias别名,如下:

resolve: {
   alias: {
    vue: 'vuehttps://img.qb5200.com/download-x/dist/vue.esm.js'
   }
  }

解决方案2

打开src/main.js修改Vue对象初始化。

new Vue({
 el: '#app',
 router,
 components: { App },
 template: '<App/>'
})

改为

new Vue({
 el: '#app',
 router,
 render: h => h(App)
})

原因是,使用 template属性,需要引入带编译器的完整版的vue.esm.js

而如果在.vue文件里面使用

<template>
 <div></div>
</template>
<script>
export default {
 name:'name1',
 data() {
  return {};
 }
};
</script>

这种形式,然后使用import引入,则不需要完整版的vue.esm.js,因为使用vue-loader时 *.vue文件会自动预编译成js。

其实vuejs官网中已有明确说明

对不同构建版本的解释(https://cn.vuejs.org/v2/guide/installation.html

其他相关文章:

理顺8个版本vue的区别(https:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们