- 名词解释 Vue.js 是完整版,是同时包含编译器和运行时的版本。
Vue.runtime.js 是运行时版,用来创建Vue实例、渲染并处理虚拟DOM等的代码,基本是完整版除去编译器的一切内容。
编译器:用来将模板字符串编译成为JavaScript渲染函数的代码。
在实际使用时,我们可以使用运行时版,配合vue-loader,既能使用户端的体积轻便,也方便实际的开发。
template和render怎么用
template的基本用法:
<template>
<div id="app">
{{n}}
<button @click="add">+1</button>
</div>
</template>
render是字符串模板的代替方案,可以最大程度的发挥JavaScript的编程能力,这个渲染函数接收一个createElement方法创建虚拟DOM
render(h){
return h('div', [this.n,h('{on:{click:this.add}’,'+1'])
}
其中,render的性能比template的性能好很多,render函数优先级大于template.
- 用 codesandbox.io 写 Vue 代码
打开codesandbox.io,点击Create Sandbox,选择Vue.