Vue專案基礎框架介紹
一、vue專案結構圖
1、build目錄是一些webpack的檔案,包括執行開發環境,專案打包等配置檔案
2、config是vue專案的基本配置檔案,webpack和node基礎,開發、線上環境的配置
3、dist是webpack打包後生成的靜態檔案目錄
4、node_modules是專案依賴的JS包
5、src專案根目錄,原始碼資料夾,基本上檔案都應該放在這裡。
6、assets 資原始檔夾,裡面放一些靜態資源
7、components專案開發的Vue元件
8、App.vue Vue專案的根元件
9、main.js Vue專案入口檔案
10、static生成好的檔案會放在這個目錄下,原始檔案,已棄用
11、.babelrc babel編譯引數,vue開發需要babel編譯
12、.editorconfig vscode相關配置
13、.gitignore 用來過濾一些版本控制的檔案,比如node_modules資料夾
14、index.html 主頁
15、package.json 專案檔案,記載著一些命令和依賴還有簡要的專案描述資訊
16、README.md 介紹自己這個專案的,想怎麼寫怎麼寫。
二、詳細介紹幾個檔案
1、package.json
package.json檔案是專案配置檔案,除了專案的一些基本資訊外,注意一下三點:
(1)dependencies:專案釋出時的依賴
(2)devDependencies:專案開發時的依賴
(3)scripts:編譯專案的一些命令
{ "name": "hydata_middleground", "version": "1.0.0", "description": "漢儀資料中臺", "author": "qiuxianhu <[email protected]>", "private": true, "scripts": { "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.jsView Code", "start": "npm run dev", "build": "node build/build.js" }, "dependencies": { "vue": "^2.5.2", "vue-router": "^3.0.1" }, "devDependencies": { "autoprefixer": "^7.1.2", "babel-core": "^6.22.1", "babel-helper-vue-jsx-merge-props": "^2.0.3", "babel-loader": "^7.1.1", "babel-plugin-syntax-jsx": "^6.18.0", "babel-plugin-transform-runtime": "^6.22.0", "babel-plugin-transform-vue-jsx": "^3.5.0", "babel-preset-env": "^1.3.2", "babel-preset-stage-2": "^6.22.0", "chalk": "^2.0.1", "copy-webpack-plugin": "^4.0.1", "css-loader": "^0.28.0", "extract-text-webpack-plugin": "^3.0.0", "file-loader": "^1.1.4", "friendly-errors-webpack-plugin": "^1.6.1", "html-webpack-plugin": "^2.30.1", "node-notifier": "^5.1.2", "optimize-css-assets-webpack-plugin": "^3.2.0", "ora": "^1.2.0", "portfinder": "^1.0.13", "postcss-import": "^11.0.0", "postcss-loader": "^2.0.8", "postcss-url": "^7.2.1", "rimraf": "^2.6.0", "semver": "^5.3.0", "shelljs": "^0.7.6", "uglifyjs-webpack-plugin": "^1.1.1", "url-loader": "^0.5.8", "vue-loader": "^13.3.0", "vue-style-loader": "^3.0.1", "vue-template-compiler": "^2.5.2", "webpack": "^3.6.0", "webpack-bundle-analyzer": "^2.9.0", "webpack-dev-server": "^2.9.1", "webpack-merge": "^4.1.0" }, "engines": { "node": ">= 6.0.0", "npm": ">= 3.0.0" }, "browserslist": [ "> 1%", "last 2 versions", "not ie <= 8" ] }
2.index.html
主頁我們可以像平時普通的html檔案一樣引入檔案和書寫基本資訊,新增meta標籤等。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>hydata_middleground</title> </head> <body> <div id="app"></div> <!-- built files will be auto injected --> </body> </html>
3.main.js
這裡是入口檔案,可以引入一些外掛或靜態資源,當然引入之前要先安裝了該外掛,在package.json檔案中有記錄。
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import App from './App' import router from './router' Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, components: { App }, template: '<App/>' })
4.App.vue
這是一個標準的vue元件,包含三個部分,一個是模板,一個是script,一個是樣式,這裡需要了解vue的基礎。
<template> <div id="app"> <img src="./assets/logo.png"> <router-view/> </div> </template> <script> export default { name: 'App' } </script> <style> #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } </style>