Vue 两个版本的区别和使用方法

186 阅读1分钟

Vue 提供了两个版本的文件

  • 完整版:同时包含编译器和运行时的版本【vue.js】
  • 运行时:用来创建 Vue 示例、默认并处理虚拟 DOM 等的代码。基本就是除去编译器的其他一切。【vue.runtime.js】
Vue 完整版Vue 非完整版
特点有 compiler没有 compiler
视图写在 HTML 里或者写在 template 选项写在 render 函数里,用 h 来创建标签
cdn 引入vue.jsvue.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 ,创建一个沙盒

wI0pfe.png

选择 Vue

wI0SYD.png

等待片刻,就可以写 Vue 代码啦

wIwzFO.png