原文链接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. GridPanel列头带有复选框的列

    由于工作需要,封装了ExtJS4,GridPanel列头带有复选框的列, 代码如下: /** * 列头带有复选框的列 * */ Ext.define("org.pine.widget.Che ...

  2. Devops Reference

    摘自 https://www.cnblogs.com/yibutian/p/9561657.html DevOps 企业实践 实施DevOps的核心目标是加速团队.企业的IT精益运行,从根本上提升IT ...

  3. Solr字段类型

    一.一般属性 1.name fieldType的名称.该值用于字段定义中的类型属性,强烈建议名称仅包含字母数字和下划线,不能以数字开头[非强制]. 2.class 用于存储和索引此类型数据的类名.可以 ...

  4. 使用focusky制作展示动画

    一个协会要举办大会议,以前我帮着做了个图片视频,就是很多照片循环展示,配个背景音乐那种. 现在又找到我,我用focusky制作下,因很久不用,怎么使用也忘了,这个软件的操作逻辑也不太容易搞的清,主要是 ...

  5. 个人第5次作业-Alpha2项目的测试

    这个作业属于哪个课程 系统分析与设计 这个作业要求在哪里 作业要求 团队名称 卓越Code 这个作业的目标 选取3个非自己所在团队进行项目测试,协助该团队进行项目改进 前言 魏家田 201731062 ...

  6. C++学习(1)—— 初识C++

    1. 变量 作用:给一段指定的内存空间起名,方便操作这段内存空间 语法:数据类型 变量名称=变量初始值​ #include<iostream> using namespace std; i ...

  7. 解决 Vue 刷新页面后 store 数据丢失的问题

    原来的状态(页面刷新数据会重置) state: { teamA: '主队' }, mutations: { data_teamA(state, x) { state.teamA = x } },   ...

  8. Go - IDE的选择与GoLand的安装

    目录 常用编辑器的选择 IDE的选择 GoLand的下载与安装 下载 安装 常用编辑器的选择 编写go程序,可以选择的编辑软件有很多,其中包括: notepad++ sublime visual st ...

  9. Linux TTY函数跟踪

    1. 介绍 本文介绍了TTY打开.TTY读和TTY写操作的函数跟踪过程 2. 示例 下面是一个简单的Linux TTY打开和读写过程 #include <termios.h> #inclu ...

  10. less-5

    首先输入id=1和id=1’未报错,均显示You are in.....(如下图所示) 由上图可以看到,如果运行返回结果正确的时候只返回you are in...,不会返回数据库当中的信息了,所以我们 ...