1. 创建新项目
$ vue init webpack my-project
执行后:
● ? Project name (my-project)
文件名(回车默认)
● ? Project description (A Vue.js project)
项目描述
● ? Author
作者
● ? Vue build (Use arrow keys)
> Runtime + Compiler: recommended for most users
Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere
选择默认
● ? Install vue-router? (Y/n)
安装 vue-router?(Vue路由功能)
● ? Use ESLint to lint your code? (Y/n)
安装 ESLint ?(语言的检查工具)
● ? Set up unit tests (Y/n)
安装单元测试?
● ? Setup e2e tests with Nightwatch? (Y/n)
安装 e2e 测试?
● ? Should we run `npm install` for you after the project has been created? (recommended)
Yes, use NPM
Yes, use Yarn
> No, I will handle that myself
(项目创建完成后,我们是否应该为您运行'npm install')选择不运行,因为已使用 cnpm,之后手动安装。
2. 进入项目:
$ cd my-project
3. 安装依赖:
$ cnpm install
安装成功
4. 运行:
$ cnpm run dev
弹出:
浏览器输入:http://localhost:8080/
出现此页面即环境搭建成功!
如果想修改端口,找到项目中 config 文件夹下的 index.js 文件,修改端口号: