一、VUE CLI介绍
1.CLI
CLI是Command-Line Interface, 翻译为命令行界面, 俗称脚手架。
Vue CLI是一个官方发布 vue.js 项目脚手架。使用 vue-cli 可以快速搭建Vue开发环境以及对应的webpack配置。
2.使用VUE CLI的前提
-
安装Node
-
安装Webpack
3.Vue CLI的使用
-
安装Vue脚手架()
npm install -g @vue/cli (-g——》global全局安装)
安装成功后检查版本:
使用脚手架2的模板时,需要安装:
-
创建CLI2项目
vue init webpack 项目名字(不能是中文)
例:
以下信息都会保存在package.json文件中:
(1)vueclitest是文件夹的名称,如果默认,项目名称会和文件夹名称一致:
(2)描述信息
(3)作者信息
(4)runtime compiler和 runtime-only的选择:
(5)路由选择:
(6)ES-lint对js代码的限制,要规范
(7)单元测试
(8)端到端测试e2e(end to end)
(9)npm or yarn
二、vue程序运行过程
runtime-compiler:
template -> ast ->render ->vdom ->UI
runtime-only:
render ->vdom ->UI
三、render函数
1.普通用法:createElement(‘标签’, {标签的属性}, [’’])
例:
return createElement('h2',
{class: 'box'},
['Hello World', createElement('button', ['按钮'])])
分析:h2为标签,class为属性
2.传入组件对象:
import APP from './App.vue'
render: function (createElement) {
return createElement(App)
}
以上代码可以直接写成
import APP from './App.vue'
render: function (h) {
return h(App)
}