1.安裝nodeJS
安裝node.js,從node.js官網下載並安裝node,安裝過程很簡單,一路“下一步”就可以了(傻瓜式安裝)。安裝完成之後,打開命令行工具(win+r,然後輸入cmd),輸入 node -v,如果出現相應的版本號,則說明安裝成功。安裝node.js後,就已經自帶npm(包管理工具)了,輸入 npm -v,出現npm版本號。
2.安裝淘寶鏡像
cmd輸入
npm install -g cnpm --registry= https://registry.npm.taobao.org
輸入 cnpm -v 出現 cnpm 版本號,安裝成功。
3.安裝webpack
cmd輸入
npm install webpack -g
輸入 webpack -v,出現版本號,安裝成功。
4.安裝vue-cli腳手架構建工具
cmd輸入
npm install vue-cli -g
輸入 vue -V(注意這裏是大寫的“V”),出現版本號,安裝成功。
5.使用vue-cli構建項目
- a. 新建一個文件夾,用於盛放項目工程;
- b. cd 到目錄路徑 ;
- c. 在cmd中輸入:
vue init webpack 你的項目名
d. cd 命令進入創建的工程目錄,cd car_code;
e. 安裝項目依賴:
npm install
- f. 安裝 vue 路由模塊 vue-router 和網絡請求模塊 vue-resource
輸入:
cnpm install vue-router vue-resource --save
6.啓動項目
輸入:
npm run dev
7.可以修改默認端口
在\config\index.js 裏面
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.HOST, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
},
在port處修改默認端口。