node的版本要求大于8.9
打开cmd或者powershell
npm install vue-cli -g
npm install @vue/cli -g
vue --version
@vue/cli 4.3.1 // 安装成功的样子
目前比较常用的有二种,今天主要介绍第一种
基于 交互式命令行
vue create 项目名
基于图形化界面
vue ui
vue create my-project
Vue CLI v4.3.1
? Please pick a preset: (Use arrow keys)
> default (babel, eslint) // 默认
Manually select features // 自定义
// 这里我们进入自定义配置,按 enter进入
? Please pick a preset: Manually select features
? Check the features needed for your project: (Press <space> to select, <a> to toggle all, <i> to invert selection)
// 空格键选中, a键全选, i键全不选
// 其中 babel、 Linter / Formatter是默认选择的
>(*) Babel // 兼容JS代码,让浏览器识别
( ) TypeScript
( ) Progressive Web App (PWA) Support // 支持渐进式网页应用程序
( ) Router // 路由管理
( ) Vuex // 状态管理
( ) CSS Pre-processors // css预处理
(*) Linter / Formatter // 代码风格、格式校验
( ) Unit Testing // 单元测试
( ) E2E Testing // 端对端测试
Vue CLI v4.3.1
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Linter // 选择的三个配置
? Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n) // 路由器想要使用历史模式吗? 选n,因为想使用hash
Vue CLI v4.3.1
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Linter
? Use history mode for router? (Requires proper server setup for index fallback in production) No
? Pick a linter / formatter config: (Use arrow keys)
> ESLint with error prevention only
ESLint + Airbnb config // airbnb 设置
ESLint + Standard config // 标准配置
ESLint + Prettier // 更漂亮的
Vue CLI v4.3.1
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Linter
? Use history mode for router? (Requires proper server setup for index fallback in production) No
? Pick a linter / formatter config: Standard
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)
// 语法规则校验
>(*) Lint on save // 选这个
( ) Lint and fix on commit
Vue CLI v4.3.1
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Linter
? Use history mode for router? (Requires proper server setup for index fallback in production) No
? Pick a linter / formatter config: Standard
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, ESLint, etc.? (Use arrow keys)
> In dedicated config files // 保存其他的配置文件,选这个
In package.json // 保存在pack.json
Vue CLI v4.3.1
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Linter
? Use history mode for router? (Requires proper server setup for index fallback in production) No
? Pick a linter / formatter config: Standard
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects?
// 将此保存为将来模板的预设,不保存就选n
下面就等项目自己安装了
(1)进入项目
cd my-project
(2)启动项目
npm run serve // 敲完之后需要等一会,启动服务器
(3)打开网站
App running at:
- Local: http://localhost:8080/ // 我们这个网址
- Network: http://192.168.1.103:8080/