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 <2269667628@qq.com>",
  "private": true,
  "scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "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"
  ]
}
View Code

 

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>

 


免責聲明!

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



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