了解vue里的Runtime Only和Runtime+Compiler
转自:了解vue里的Runtime Only和Runtime+Compiler
扩展文章:Vue 2.0如何仅使用Runtime-only Build构建项目?

可以看到有两种版本: Runtime Only 版本 和 Runtime+Compiler 版本。
1.Runtime Only
我们在使用 Runtime Only 版本的 Vue.js 的时候,通常需要借助如 webpack 的 vue-loader 工具把 .vue 文件编译成 JavaScript,因为是在编译阶段做的,所以它只包含运行时的 Vue.js 代码,因此代码体积也会更轻量。 在将 .vue 文件编译成 JavaScript的编译过程中会将组件中的template模板编译为render函数,所以我们得到的是render函数的版本。所以运行的时候是不带编译的,编译是在离线的时候做的。
2.Runtime+Compiler
我们如果没有对代码做预编译,但又使用了 Vue 的 template 属性并传入一个字符串,则需要在客户端编译模板,如下所示:
// 需要编译器的版本
new Vue({
template: '{{ hi }}'
})
// 这种情况不需要
new Vue({
render (h) {
return h('div', this.hi)
}
})
因为在 Vue.js 2.0 中,最终渲染都是通过 render 函数,如果写 template 属性,则需要编译成 render 函数,那么这个编译过程会发生运行时,所以需要带有编译器的版本。
很显然,这个编译过程对性能会有一定损耗,所以通常我们更推荐使用 Runtime-Only 的 Vue.js。
只有以下情况会用到compiler:
1.有指定template;
2.没指定template,也没指定render(这时候使用的就是被挂载元素的outerHtml)。
所以,没有使用到compiler的情况只有:没有指定template,但指定了render。
有时会遇到这样的错误:
[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(runtime+compiler),这个版本的vue文件相比仅包含runtime的版本体积要大,而且运行时的compiler转换会消耗性能,compiler过程其实可以放到构建过程中进行。
总结就是,如果可以的话,尽量使用runtime版的vue文件。
了解vue里的Runtime Only和Runtime+Compiler的更多相关文章
- eclipse里error报错Target runtime com.genuitec.runtime.generic.jee60 is not defined.
eclipse里error报错Target runtime com.genuitec.runtime.generic.jee60 is not defined. eclipse里error报错解决办法 ...
- Mac下 eclipse target runtime com.genuitec.runtime 解决方法
Mac下 eclipse target runtime com.genuitec.runtime 解决方法 解决步骤如下: 首先是找到工程项目一个名叫.settings的文件夹,里面有个叫 org.e ...
- Target runtime com.genuitec.runtime.generic.jee60 is not defined
转载自:http://jingyan.baidu.com/article/d7130635338e3f13fdf47518.html 用eclipse加载别人的工程,报错Target runtime ...
- Target runtime com.genuitec.runtime.generic.jee50 is not defined
导入别人的工程,发现报错Target runtime com.genuitec.runtime.generic.jee50 is not defined 解决方法:1. 找到工程目录的.setti ...
- 用eclipse加载别人的工程,报错Target runtime com.genuitec.runtime.generic.jee60 is not defined
系统加载工程后,报错Target runtime com.genuitec.runtime.generic.jee60 is not defined,在发布工程的同事电脑上正常 新导入的工程,出问题很 ...
- vue里在自定义的组件上定义的事件
事件分为原生事件和自定义事件. vue里在自定义的组件上定义的事件,都被认为是自定义事件,必须用$emit()来触发. 这也是子组件向父传值的原理. 如果想作为原生事件,需要在原生事件后面加上.nat ...
- vue里的渲染以及computed的好处
如果vue里的某个methods函数执行,导致页面重新渲染,那么所有页面渲染相关的methods函数会重新执行以及时的渲染页面 但是大量函数的重新没有必要的执行会导致性能的下降, 此时如果把没有必要再 ...
- bug4 导入新工程时报 Target runtime com.genuitec.runtime.generic.jee60 is not defined
系统加载工程后,报错Target runtime com.genuitec.runtime.generic.jee60 is not defined,在发布工程的同事电脑上正常.新导入的工程,出问题很 ...
- vue里的数据
背景: 一个项目完工在即,鉴于此,前端使用了vue,写下此栏,以供日后翻阅, 会涉及到我所运用到的vue相关知识,需要一定的js基础. 默认vue的single-file-components(单文件 ...
随机推荐
- SQL FIRST() 函数
FIRST() 函数 FIRST() 函数返回指定的字段中第一个记录的值. 提示:可使用 ORDER BY 语句对记录进行排序. SQL FIRST() 语法 SELECT FIRST(column_ ...
- resnet代码分析
1. 先导入使用的包,并声明可用的网络和预训练好的模型 import torch.nn as nn import torch.utils.model_zoo as model_zoo #声明可调用的网 ...
- 《你必须掌握的Entity Framework 6.x与Core 2.0》勘误
第5章 5.1.1----致谢网友[宪煌] public virtual ICollection Post {get;set;} 修改为 public virtual ICollection<P ...
- 石家庄地铁系统开发(java web版)(一)
今天所完成的任务: 在Mysql数据库中创建了sjzsubstop表和sjzsubway表 sjzsubstop表用于录入所有站点名称和与之对应的stopid(作为主码) sjzsubway表用于录入 ...
- 验证码的实现py3
import randomflag = 1try_=0while (flag): try_ +=1 yan = "" for i in range(0,4): cun=random ...
- CSS3 border-radius 圆角
圆角border-radius,其css如下 IE9+支持(就是ie6,ie7,ie8都不支持),默认值是0,不继承,可以像下面那样设置4个角的值,也可以单独设置,如 border-top-left- ...
- FJUTOJ-周赛2016-12-16
注:fjutoj基本每周都有一次周赛,欢迎大家都来参加! 网址:http://59.77.139.92/index.jsp A题:来源 POJ 2773 题意:给两个数m和k,问第k 个和m 互素的数 ...
- React Native & iframe & WebView
React Native & iframe & WebView React Native 怎么渲染 iframe 页面 WebView & source html https: ...
- java 基本数据类型初始值(默认值)
1.int类型定义的数组,初始化默认是0 2.String类型定义的数组,默认值是null 3.char类型定义的数组,默认值是0对应的字符 4.double类型定义的数组,默认值是0.0 5.flo ...
- Spring 事务传播特性
Spring 事务属性一共有四种:传播行为.隔离级别.只读和事务超时 a) 传播行为定义了被调用方法的事务边界. 传播行为 意义 PROPERGATION_MANDATORY 表示方法必须运行在一 ...