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启动时就会被创建,并且它的实际的物理内存 ...
随机推荐
- (六)SpringBoot整合Swagger2框架
一:什么是Swagger Swagger是一款通过我们添加的注解来对方法进行说明,来自动生成项目的在线api接口文档的web服务. 二:添加Swagger2依赖 <dependency> ...
- jQuery中$.getJSON
$.getJSON $.getJSON()是专门为ajax获取json数据而设置的,并且支持跨域调用,其语法的格式为: $.getJSON( url, //请求URL [data], //传参,可选参 ...
- 如何访问google?
1:浏览器打开 uzer.me 网站(建议:火狐,不行就谷歌) 2:点击注册,注册一个账号 3:登录账号,进入如下界面,选择火狐浏览器 4:这样就可以进行国外的网站访问了
- centos7上使用locate命令-文件查找
centos7上使用locate命令 小贴士:在centOS7以上的系统中使用“locate”文件查找命令,发现该命令不可用. 检查了下,原来是centos7默认没有安装该命令,在联网状态运行“y ...
- queue POJ 2259 Team Queue
题目传送门 题意:先给出一些小组成员,然后开始排队.若前面的人中有相同小组的人的话,直接插队排在同小组的最后一个,否则只能排在最后面.现在有排队和出队的操作. 分析:这题关键是将队列按照组数分组,用另 ...
- 题解报告:hdu 2196 Computer(树形dp)
Problem Description A school bought the first computer some time ago(so this computer's id is 1). Du ...
- dubbo中Hessian方法重载问题处理
dubbo中Hessian方法重载,报出如下错误信息: 十一月 , :: 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Ser ...
- 生产环境中nginx既做web服务又做反向代理
一.写对于初入博客园的感想 众所周知,nginx是一个高性能的HTTP和反向代理服务器,在以前工作中要么实现http要么做反向代理或者负载均衡.尚未在同一台nginx或者集群上同时既实现HTTP又实现 ...
- OCP 11g 第四章练习
练习 4-1 配置Oracle Net 在本练习中, 将使用图形化工具和命令行工具来建立一个完整的Oracle Net 环境. 由此, 读者可看出在Windows 和 Linux 系统中的区别. 1. ...
- RFS自动化测试(一)
RFS 即 Robot Framework + Selenium RFS 的安装 1. python https://www.python.org/ RF框架是基于python的,所以要先安装有pyt ...