vue 运行时 + 编译器 vs. 只包含运行时
https://cn.vuejs.org/v2/guide/installation.html#运行时-编译器-vs-只包含运行时
文档中的这个地方,说的不清楚
If you need to compile templates on the client (e.g. passing a string to the
templateoption, or mounting to an element using its in-DOM HTML as the template), you will need the compiler and thus the full build
这部分的意思是对于以下情况会用到compiler:
有指定template
没指定template,也没指定render(这时候使用的就是被挂载元素的outerHtml)
所以,没有使用到compiler的情况只有:没有指定template,但指定了render。 这种情况并没有画到vue的生命周期图里,真的不容易发现。
有时候我们会遇到这样的错误:
[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.
以上提到,解决这个问题有两种方式。到谷歌必应上搜索,99%的都选择了后者,也就是使用全功能的vue(runtime+compiler),这个版本的vue文件相比仅包含runtime的版本体积要大,而且运行时的compile转换会消耗性能,compile过程其实可以放到构建过程中进行。
总结就是:如果可以的话,尽量使用runtime版的vue文件。
以下演示一个简单的runtime版vue项目 :
项目初始化,前三个依赖是vue-loader的必备依赖
npm init -y && npm install --save-dev css-loader vue-loader vue-template-compiler vue
其余文件
// app.vue
<style scoped>
.title{
color:red;
text-align: center;
}
</style> <template>
<div class="title">
这是标题
</div>
</template> <script>
alert("标题初始化")
</script> // index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="root">
<app></app>
</div>
</body>
<script src="bundle.js"></script>
</html> // main.js
import Vue from 'vue'
import app from './app.vue' // new Vue({
// el:"#root",
// render:function(c){
// return c("app")
// },
// components:{
// app
// }
// }); // 两种初始化方式都可以
new Vue(app).$mount("#root"); // webpack.config.js
module.exports = {
entry: {
bundle: './main.js'
},
output: {
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
resolve: {
extensions: [".vue",".js",".json"],
alias: {
'vue$': 'vue/dist/vue.runtime.js',
}
},
};
以上项目能正常运行。
compiler的作用在webpack引入 .vue文件的时候,就调用vue-loader来预处理过了,所以到了浏览器端运行的时候,仅仅引入vue.runtime就可以了
vue 运行时 + 编译器 vs. 只包含运行时的更多相关文章
- Create a Report at Runtime 在运行时创建报表
In this lesson, you will learn how to create reports at runtime. A report showing a list of Tasks wi ...
- 在 Ubuntu 上安装 .NET SDK 或 .NET 运行时
在wsl Ubuntu 20.04上面安装dotnet链接 https://docs.microsoft.com/zh-cn/dotnet/core/install/linux-ubuntu Ubun ...
- xmake v2.6.1 发布,使用 Lua5.4 运行时,Rust 和 C++ 混合编译支持
xmake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能 ...
- 大白话Vue源码系列(05):运行时鸟瞰图
阅读目录 Vue 实例的生命周期 实例创建 响应的数据绑定 挂载到 DOM 节点 结论 研究 runtime 一边 Vue 一边源码 初看 Vue 是 Vue 源码是源码 再看 Vue 不是 Vue ...
- clr(Windows 运行时和公共语言运行时)
Windows 运行时 编译器使用 COM 引用计数机制来确定对象是否不再使用并可以删除. 因为从 Windows 运行时接口派生的对象实际上是 COM 对象,所以这是可行的. 在创建或复制对象时 ...
- Visual C++中对运行时库的支持
原文地址:http://blog.csdn.net/wqvbjhc/article/details/6612099 一.什么是C运行时库 1)C运行时库就是 C run-time library,是 ...
- C运行时库(C Run-time Library)详解(提供的另一个最重要的功能是为应用程序添加启动函数。Visual C++对控制台程序默认使用单线程的静态链接库,而MFC中的CFile类已暗藏了多线程)
一.什么是C运行时库 1)C运行时库就是 C run-time library,是 C 而非 C++ 语言世界的概念:取这个名字就是因为你的 C 程序运行时需要这些库中的函数. 2)C 语言是所谓的“ ...
- [转帖]运行时库(runtime library)
运行时库(runtime library) https://blog.csdn.net/xitie8523/article/details/82712105 没学过这些东西 或者当时上课没听 又或者 ...
- JVM运行时数据区--方法区
运行时数据区结构图(温习): 堆.栈.方法区的交互关系 方法区的理解 方法区(Method Area)与Java堆一样,是各个线程共享的内存区域 方法区在JVM启动时就会被创建,并且它的实际的物理内存 ...
随机推荐
- 【EXCEL终极总结分享】基于NPOI扩展封装的简易操作工具类库(简单灵活易用,支持导出、导入、上传等常见操作)
对于EXCEL的导入.导出,我之前已分享过多次,比如: 第一种方案:<我写的一个ExcelHelper通用类,可用于读取或生成数据>这个主要是利用把EXCEL当成一个DB来进行获取数据,导 ...
- 键值编码 KVC
http://www.cnblogs.com/dyf520/p/3805297.html 1,什么是Key-Value Coding? Key-Value Coding是一种间接访问对象属性的机制,使 ...
- 学习Mahout(一)
Mahout 官方下载地址:http://apache.fayea.com/apache-mirror/mahout/ 环境ubuntu 12.04, hadoop1.2.1 ,mahout 0.9 ...
- pyinstaller模块
应用场景: 1 把一些python脚本推广到更多机器上运行,但无法保证他们都有安装python解释器,所以,打包可以免去这一障碍 win: 安装: 在cmd中运行pip install pyinsta ...
- BZOJ4974(给Next求最小字典序原串)
输入给出了最小循环节长度,暗示next数组. 然后自己按照自己的kmp板子逆着来一遍就好. ; int n, a, Next[maxn]; char str[maxn]; ]; int main() ...
- [BZOJ3916/WOJ3815]Friends
题目链接: 传送门 题目: Description 有三个好朋友喜欢在一起玩游戏,A君写下一个字符串S,B君将其复制一遍得到T,C君在T的任意位置(包括首尾)插入一个字符得到U.现在你得到了U,请你找 ...
- AWVS11使用教程——Acunetix Web Vulnerability Scanner 11.x
AWVS11使用教程 一:普通扫描. 二:报告生成. 三:登陆扫描. Acunetix Web Vulnerability Scanner(简称AWVS)是一款知名的网络漏洞扫描工具,它通过网络爬虫测 ...
- 简单了解Linux中 du 和 df 以及它们的区别
一 .du : 显示每个文件和目录的磁盘使用空间~~~文件的大小. 命令参数: -a #显示目录中文件的大小 单位 KB . -b #显示目录中文件的大小,以字节byte为单位. -c #显 ...
- C#基础学习5
数组集合
- 如何使用 Java 生成二维码
步骤 下载jar包(QRCode.jar) maven项目手动引入jar包 编写实体类实现二维码的生成 controller调用 下载jar包(QRCode.jar) 下载网址如下: QRCode生成 ...