日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

Vue 脚手架CLI 初始化项目

發布時間:2025/5/22 vue 189 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Vue 脚手架CLI 初始化项目 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1 介紹

  • CLI是Command-Line Interface,翻譯為命令行界面,但是俗稱腳手架。

  • Vue CLI是一個官方發布vue.js項目腳手架

  • 使用vue-cli可以快速搭建vue開發環境以及對應的webpack配置。

  • 使用vue-cli可以快速搭建vue開發環境以及對應的webpack配置

2 Vue CLI使用前提 Webpack

Vue.js官方腳手架工具就使用了webpack模板

  • 對所有的資源會壓縮等優化操作

  • 它在開發的過程中提供了一套完整的功能,能夠使得我們開發過程變得高效

Webpack全局安裝

npm install webpack -g

3 Vue CLI安裝

https://cli.vuejs.org/zh/guide/

3.1 安裝腳手架3.x

安裝Vue腳手架(全局)

# 腳手架3.x(后面拉一個模板就能用2) npm install -g @vue/cli

注意:上面安裝的是Vue CLI3的版本,如果需要按照Vue CLI2的方式初始化項目時不可以的

查看版本

vue --version

Vue CLI3.x初始化項目

vue create my-project

3.2 拉取腳手架2.x

拉取腳手架2.x官方教程

npm install -g @vue/cli-init # `vue init` 的運行效果將會跟 `vue-cli@2.x` 相同 vue init webpack my-project

Vue CLI2初始化項目

vue init webpack my-project

4 常用命令

打包項目

npm run build

運行項目

npm run serve

6 其他常用文件

.editorconfig

# 編輯器配置 root = true[*] charset = utf-8 indent_style = space indent_size = 2 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true

.eslintrc

// https://eslint.org/docs/user-guide/configuring // eslint是用來管理和檢測js代碼風格的工具,可以和編輯器搭配使用, // 如vscode的eslint插件 當有不符合配置文件內容的代碼出現就會報錯或者警告module.exports = {root: true,parserOptions: {parser: 'babel-eslint'},env: {browser: true,},extends: [// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.'plugin:vue/essential',// https://github.com/standard/standard/blob/master/docs/RULES-en.md// 'standard'],// required to lint *.vue filesplugins: ['vue'],// add your custom rules hererules: {"no-unused-vars": 'off', // 關掉語法檢查// allow async-await'generator-star-spacing': 'off',// allow debugger during development'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'} }

5 實戰

  • "vue": "^2.6.11"( package.json中 )
  • @vue/cli 4.5.15( vue -V 查看 )

創建項目

vue create my-project

修改 package.json

"dependencies": {// 修改下面"vue": "^2.6.11", }, "devDependencies": {// 修改下面"vue-template-compiler": "^2.6.11" }

修改main.js

import Vue from 'vue' import App from './App.vue' import router from './router'// 餓了么 import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css';Vue.use(ElementUI);Vue.config.productionTip = falsenew Vue({router,render: h => h(App), }).$mount('#app')

router/index.js

import Vue from 'vue' import VueRouter from 'vue-router'// import Test from "../views/Test";Vue.use(VueRouter)const routes = [// component: () => import('../views/Ajax.vue'){path: '/',name: 'Test',component: () => import('../views/Test.vue')} ]const router = new VueRouter({// mode: 'history',base: process.env.BASE_URL,routes })export default router

7 第三方安裝

vue-router

npm install --save vue-router

axios

npm install --save axios

餓了么

npm i element-ui -S npm install --save element-ui

echarts
Vue引用echarts圖表

npm install echarts --save

原文:https://www.920vip.net/article/162

總結

以上是生活随笔為你收集整理的Vue 脚手架CLI 初始化项目的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。