寄語:vue的安裝不是理想化的,會出現不少問題,須要靜下心認真研究,熬過去就會懂得更多,如下是我遇到的問題和最真摯的建議,按照個人方法不會出錯,必定會成功,我嘗試了不少次方式,查閱了不少資料,最終總結出這篇vue安裝經驗,感謝閱讀,送給同感之人。html
1.安裝node,點擊連接:https://nodejs.org/en/download/ vue
a.必定要從官網下載node
b.放置D盤一級目錄下webpack
c.選擇Add to PATH(默認會添加到path環境變量中)web
npm: Nodejs下的包管理器。vue-router
webpack: 它主要的用途是經過CommonJS的語法把全部瀏覽器端須要發佈的靜態資源作相應的準備,好比資源的合併和打包。vue-cli
vue-cli: 用戶生成Vue工程模板。(幫你快速開始一個vue的項目,也就是給你一套vue的結構,包含基礎的依賴庫,只須要 npm install就能夠安裝)npm
開始:
![](http://static.javashuo.com/static/loading.gif)
如圖,下載8.9.3 LTS (推薦給絕大部分用戶使用json
![](http://static.javashuo.com/static/loading.gif)
雙擊安裝
![](http://static.javashuo.com/static/loading.gif)
能夠使用默認路徑,本例子中自行修改成d:\nodejs
![](http://static.javashuo.com/static/loading.gif)
一路點Next
![](http://static.javashuo.com/static/loading.gif)
點Finish完成
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
打開CMD,檢查是否正常
![](http://static.javashuo.com/static/loading.gif)
2.查看node和npm版本瀏覽器
a.node -v
b.npm -v(此版本node自帶)
c.更新npm版本
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
而後運行如下2條命令
npm config set prefix "D:\nodejs\node_global"
npm config set cache "D:\nodejs\node_cache"(若安裝失敗,手動創建node_cache項目文件)
![](http://static.javashuo.com/static/loading.gif)
如上圖,咱們再來關注一下npm的本地倉庫,輸入命令npm list -global
![](http://static.javashuo.com/static/loading.gif)
輸入命令npm config set registry=http://registry.npm.taobao.org 配置鏡像站
![](http://static.javashuo.com/static/loading.gif)
輸入命令npm config list 顯示全部配置信息,咱們關注一個配置文件
C:\Users\Administrator\.npmrc
![](http://static.javashuo.com/static/loading.gif)
使用文本編輯器編輯它,能夠看到剛纔的配置信息
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
檢查一下鏡像站行不行命令1
輸入:npm config get registry
![](http://static.javashuo.com/static/loading.gif)
檢查一下鏡像站行不行命令2
看看可否得到vue的信息,輸入:Npm info vue
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
注意,此時,默認的模塊D:\nodejs\node_modules 目錄
將會改變爲D:\nodejs\node_global\node_modules 目錄,
3.若是直接運行npm install等命令會報錯的。
咱們須要作1件事情:
一、增長環境變量NODE_PATH 內容是:D:\nodejs\node_global\node_modules
![](http://static.javashuo.com/static/loading.gif)
(注意,一下操做須要從新打開CMD讓上面的環境變量生效)
1、測試NPM安裝vue.js
輸入命令:npm install vue -g
這裏的-g是指安裝到global全局目錄去
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
2、測試NPM安裝vue-router
輸入命令:npm install vue-router -g
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
安裝vue腳手架,輸入運行:npm install vue-cli -g
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
編輯環境編輯path
![](http://static.javashuo.com/static/loading.gif)
備註:對path環境變量添加D:\nodejs\node_global
win10如下版本的,橫向顯示PATH的,注意添加到最後時,不要有分號【;】
四.測試vu,搭建vue項目
![](http://static.javashuo.com/static/loading.gif)
從新打開CMD,而且測試vue是否使用正常
![](http://static.javashuo.com/static/loading.gif)
注意:vue-cli工具是內置了模板包括 webpack 和 webpack-simple,前者是比較複雜專業的項目,
他的配置並不全放在根目錄下的 webpack.config.js 中。
![](http://static.javashuo.com/static/loading.gif)
初始化,安裝依賴
![](http://static.javashuo.com/static/loading.gif)
安裝依賴,輸入運行:npm install
![](http://static.javashuo.com/static/loading.gif)
運行vue項目程序。輸入:npm run dev
![](http://static.javashuo.com/static/loading.gif)
成功界面,提示打開地址,瀏覽器複製:http://localhost:8080
![](http://static.javashuo.com/static/loading.gif)
設置自動打開瀏覽器,輸入:npm run build
![](http://static.javashuo.com/static/loading.gif)
生成靜態文件,打開dist文件夾下新生成的index.html文件
nmp下新建出來的vue01的目錄描述:
![](http://static.javashuo.com/static/loading.gif)
注意:如出現2種狀況,輸入對應的命令行:
1. Error npm vue-cli3 這種錯誤。安裝sass,請輸入命令:npm install node-sass --save-dev (使用save會在package.json中自動添加,安裝淘寶鏡像)
npm install sass-loader --save-dev
2.vue項目沒法運行,模塊沒法加載,找不到(由於環境變量有變更),須要從新加載模塊,請輸入命令:Npm rebuild node-sass
cnblogs.com/crazycode2/p/6535105.html