当前位置: 移动技术网 > IT编程>脚本编程>vue.js > 关于vue编译版本引入的问题的解决

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

2018年09月23日  | 移动技术网IT编程  | 我要评论

邪皇抢亲 冷情特种妃,小学数学课件,石家庄美食团购网

下班过目遇到一个错误

[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: 'vue/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#%e5%af%b9%e4%b8%8d%e5%90%8c%e6%9e%84%e5%bb%ba%e7%89%88%e6%9c%ac%e7%9a%84%e8%a7%a3%e9%87%8a

其他相关文章:

理顺8个版本vue的区别()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网