对Vue脚手架搭建工程结构的理解

  • 1.运行npm run dev 在当前目录下找到package.json来启动一个服务,该文件记录了工程依赖包的版本信息,指定了npm run dev执行的js文件为:build目录下的webpack.dev.conf.js
    2478673-e4ba83986a5ccc5b.png
    B88CF028-E513-4F16-B9C4-8EE9220AE185.png
  • 2.执行webpack.dev.conf.js:引入依赖的中间件,并启动一个服务,指定加载index.html文件

2478673-8b91622f91a08b71.png
B11F9C1F-8765-4C8E-A15E-7032FC86DB6B.png
  • 3.index.html: 在body中提供一个绑定id=''app''的div标签,与后面main.js创建的vue实例相关联。
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>seudweb</title>
  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

4.main.js:创建Vue实例,引入了vue,App和router

  • App:主组件,其他单页面组件可以看成他的子组件,因为App.vue中的<router-view/>标签存放所有路由文件
  • router:路由
// 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/>'
})

5.App.vue:主组件

<template>
  <div id="app">
    <img src="./assets/images/logo.png">
    <div>放些公共的部分在这里</div>
    <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>

转载于:https://www.jianshu.com/p/3fe3a874d088

猜你喜欢

转载自blog.csdn.net/weixin_34032621/article/details/91165543
今日推荐