Vue 提供了两个版本的文件
- 完整版:同时包含编译器和运行时的版本【vue.js】
- 运行时:用来创建 Vue 示例、默认并处理虚拟 DOM 等的代码。基本就是除去编译器的其他一切。【vue.runtime.js】
| Vue 完整版 | Vue 非完整版 | |
|---|---|---|
| 特点 | 有 compiler | 没有 compiler |
| 视图 | 写在 HTML 里或者写在 template 选项 | 写在 render 函数里,用 h 来创建标签 |
| cdn 引入 | vue.js | vue.runtime.js |
| webpack 引入 | 需要配置 alias | 默认使用此版 |
| @vue/cli引入 | 需要额外配置 | 默认使用此版 |
使用完整版
new Vue({
template: `<div>{{ hi }}</div>` // 书写html模版
})
使用运行时版
new Vue({
render(h) {
return h('div', this.hi)
}
})
使用 codesandbox.io 写代码
点击 Create Sandbox ,创建一个沙盒
选择 Vue
等待片刻,就可以写 Vue 代码啦