原文链接https://blog.csdn.net/xiaomajia029/article/details/88320233

问题描述:

原因分析:
在项目配置的时候,默认 npm 包导出的是运行时构建,即 runtime 版本,不支持编译 template 模板。

vue 在初始化项目配置的时候,有两个运行环境配置的版本:Compiler 版本、Runtime 版本。

其主要区别在于:

Compiler 版本:
可以对 template 模板内容进行编译(包括字符串模板和可以绑定的 html 对象作为模板),例如:

new Vue({
el: "#box",
template: "<div>{{msg}}</div>",
data: {
msg: "hello"
}
});
Runtime 版本:
使用 vue-loader 加载.vue 文件(组件文件)时,webpack 在打包过程中对模板进行了渲染。

解决方法
修改配置文件中的 vue 引用

一、 vue cli 2.x
找到 webpack.base.conf.js 文件,修改以下配置:

在 webpack.base.conf.js 配置文件中多加了一段代码,将 vue/dist/ package.json 配置文件的"main": "dist/vue.runtime.common.js",改为引用代码中的引用 vue/dist.vue.esm.js 文件,意思就是说 webpack.base.conf.js 这个文件已经将 vue/dist.package.json 的错误引用纠正成 vue/dist.vue.esm.js

// ...
const config = {
// ...
resolve: {
extensions: [".js", ".vue", ".json"],
alias: {
vue$: "vue/dist/vue.esm.js",
"@": resolve("src")
}
}
};
二、 vue cli 3.x
修改项目根目录中的配置文件:vue.config.js,具体代码如下:

修改 vue_cli3.0 的配置文件,添加 配置文件:vue.config.js 在项目的根目录下,目的是修改在引入 vue 时,不要采用 runtime 形式的文件,而采用 dist/vue.esm.js 形式文件

// ...

module.exports = {
// ...

configureWebpack: config => {
config.resolve = {
extensions: [".js", ".vue", ".json", ".css"],
alias: {
vue$: "vue/dist/vue.esm.js",
"@": resolve("src")
}
};
}

// ...
};
【划重点】

发现了一个新的方法,只需要添加一行代码的配置,即可实现支持template编译:

// vue.config.js

module.exports = {
runtimeCompiler: true,
}
 
————————————————
版权声明:本文为CSDN博主「@xiaomajia」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xiaomajia029/article/details/88320233

[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available的更多相关文章

  1. vue.runtime.esm.js:593 [Vue warn]: Invalid prop: custom validator check failed for prop "value".报错解决

    在uni中使用 picker组件,一直报错 vue.runtime.esm.js:593 [Vue warn]: Invalid prop: custom validator check failed ...

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

    转载自:https://segmentfault.com/a/1190000006435886 解决办法:添加package.config.js配置文件中,添加本文章的红色部分代码 import vu ...

  3. // mounted: {}, 原来是 空方法 导致了 vue 的警告 !| [Vue warn]: Error in mounted hook: "TypeError: handlers[i].call is not a function"

    // mounted: {}, 原来是 空方法 导致了 vue 的警告 !| vue.runtime.esm.js?2b0e:587 [Vue warn]: Error in mounted hook ...

  4. vue报错[Vue warn]: Unknown custom element: <router-Link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

    vue浏览器报错,如下 vue.runtime.esm.js?2b0e:619 [Vue warn]: Unknown custom element: <router-Link> - di ...

  5. vue踩坑记录:[Vue warn]: $attrs is readonly.

    今天在用element-ui的DatePicker日期选择器的时候,发现每当点击一次这个组件,控制台就会报警告`[Vue warn]: $attrs is readonly`,但是也不影响实际操作效果 ...

  6. [Vue warn]: Attribute "id" is ignored on component <div> because the component is a fragment instanc

    今天在使用vue框架搭建环境时,遇到这个错误提示: [Vue warn]: Attribute "id" is ignored on component <div> b ...

  7. [Vue warn]: Cannot find element: #main

    使用vue框架的时候,如果页面提示如下错误,则说明new Vue的时候没有传入 el 的值: [Vue warn]: Cannot find element: #main 我们传入el 既可以,如: ...

  8. [Vue warn]: Error in render: "SyntaxError: Unexpected token ' in JSON at position 1"

    一,场景: 字符串转对象: var str = "{'bankRate':5,'YINGUO':0}" 二,操作: JSON.parse(str)时候,报错 [Vue warn]: ...

  9. [Vue warn]: Do not mount Vue to <html> or <body> - mount to normal elements instead.

    官方文档是这么解释的: 提供的元素只能作为挂载点.不同于 Vue 1.x,所有的挂载元素会被 Vue 生成的 DOM 替换.因此不推荐挂载root实例到 <html> 或者 <bod ...

  10. [Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined、vuejs路由使用的问题Error in render function

    1.[Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined 注意,只要出现Error i ...

随机推荐

  1. 140款Android开源优秀项目源码

    BeautifulRefreshLayout-漂亮的美食下拉刷新 https://github.com/android-cjj/BeautifulRefreshLayout/tree/Beautifu ...

  2. CspParameters 对象已存在异常 解决多应用对同一容器的访问问题

    CspParameters cspParams; cspParams = new CspParameters(PROVIDER_RSA_FULL); cspParams.KeyContainerNam ...

  3. 11g包dbms_parallel_execute在海量数据处理过程中的应用

    11g包dbms_parallel_execute在海量数据处理过程中的应用 一.1  BLOG文档结构图 一.2  前言部分 一.2.1  导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也 ...

  4. 多线程之美6一CAS与自旋锁

    1.什么是CAS CAS 即 compare and swap 比较并交换, 涉及到三个参数,内存值V, 预期值A, 要更新为的值B, 拿着预期值A与内存值V比较,相等则符合预期,将内存值V更新为B, ...

  5. 执行chmod -R 777 / 补救

    执行后千万不要退出当前窗口!!! 在自己的虚拟机上设置某个站的权限的时候,原来应该是chmod -R 777 ./*  结果少按了个点,执行了chmod -R 777 /*  因为执行时间超出自己的预 ...

  6. SpringCloud2.0 Hystrix Dashboard 断路器指标看板 基础教程(八)

    1.启动基础工程 1.1.启动[服务中心]集群,工程名称:springcloud-eureka-server 参考 SpringCloud2.0 Eureka Server 服务中心 基础教程(二) ...

  7. 状压dp之位运算

    ## 一.知识 1.我们知道计算机中数据由二进制数存储,一个二进制数的一位就是计算机中数据的最小单位bit,我们有一种运算符可直接对二进制数进行位运算,所以它的速度很快. 2.C++中的位运算符有6种 ...

  8. postgres高可用学习篇二:通过pgbouncer连接池工具来管理postgres连接

    安装pgbouncer yum install libevent -y yum install libevent-devel -y wget http://www.pgbouncer.org/down ...

  9. shell脚本自动化安装pgsql10.5版本

    看到有个大佬写了个很实用的脚本,于是这里做了转载 #!/bin/bash #进入软件的制定安装目录 echo "进入目录/usr/local,下载pgsql文件" cd /usr/ ...

  10. Convert 输入字符串的格式不正确

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...