vue 項目安裝 (入門)


由於vue越來越受歡迎,終於還是決定開始學習vue了。在前端這個行業,如果你不抓緊學習前沿技術,那么你會恐懼的發現自己生活在遠古時代。

哈哈,跑偏了,第一次接觸vue,內心是激動的。

按我的習慣,先上git,找個不錯的項目研究研究。畢竟,站在巨人的肩膀,可以看得更遠。
選了這位大神的項目https://github.com/bailicangdu/vue2-elm

按着項目運行步驟:

git clone https://github.com/bailicangdu/vue2-elm.git  

cd vue2-elm

npm install

npm run dev (訪問線上后台系統)

冷冷的冰雨在臉上胡亂的拍。。。各種報錯!!!

一定是我的打開方式不對,內牛滿面。

又各種查閱資料,不斷嘗試,終於可以了。

這么刻骨銘心的經歷,一定要分享出來,哈哈哈。

1. 檢查是否已經安裝了node和npm;

2..安裝 vue-cli;

npm install -g vue-cli        // 安裝
vue                           // 查看,這里會出現一些用法,指令之類的訊息
vue list                      // 會出現browserify , webpack 模板相關的訊息

3. 克隆vue2-elm項目到你指定的文件夾vueJs下;

cd vueJs
git clone https://github.com/bailicangdu/vue2-elm.git  

4. 在vueJs文件夾下,初始化模板,選擇 webpack作為打包工具。

一般來說,語法是這樣的: vue init 模板名 項目名稱
(項目已存在,此步驟可跳過。)

vue init webpack vue2-elm              //默認為2.0了
// vue init webpack#1.0 sell1.0       //則為1.0版本
// 期間會有一些選項的設置
1. vue init webpack pname(你的項目名字);

2. ? Project description (A Vue.js project) 新建項目(項目描述);

3. ? Author (xxx) ;xxx(項目作者);

4. ? Vue build
❯ 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
**這里選擇Runtime + Compiler: recommended for most users;**

5. ? Install vue-router? (Y/n) y 是否使用vue-router,這里根據需求選擇;

6. ? Use ESLint to lint your code? (Y/n) y 是否使用ESLint,這里根據需求選擇;

7. ? Pick an ESLint preset (Use arrow keys)
❯ Standard (https://github.com/feross/standard)
Airbnb (https://github.com/airbnb/javascript) none (configure it yourself)
**這里選擇Standard (https://github.com/feross/standard)**

8. ? Setup unit tests with Karma + Mocha? (Y/n) n 是否需要單元測試,這里根據需求選擇;
 
9. Setup e2e tests with Nightwatch? (Y/n) n是否需要單元測試,這里根據需求選擇;

5. 安裝並運行模板

(1) 進入vue2-elm項目文件夾;

cd vue2-elm

(2) 安裝vue2-elm項目;

npm install            // install 過程會比較慢,因為要下載一些依賴包(當然你也可以選擇 cnpm 安裝),完成后 目錄下 會多了一個 node_modules 文件夾

(3) 修改vue2-elm項目端口;

由於項目默認端口為8080,在我的電腦上已被占用。所以,需要修改端口配置。

項目結構:

- vue2-elm
        - build
        - config
            - index.js
        - elm
        - node_modules
        - screenshots
        - src
        - vue2-elm
        。。。

在config文件夾下的index.js里,有項目的配置信息。
修改port,為你想設置的端口,即可。

  dev: {
    env: require('./dev.env'),
    port: 9200,
    autoOpenBrowser: true,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},
    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false
  }

(4) 運行vue2-elm項目;

npm run dev         

然后你的默認瀏覽器,華麗麗的打開了項目的首頁。

不容易呀,配置這些環境。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM