-
2.执行webpack.dev.conf.js:引入依赖的中间件,并启动一个服务,指定加载index.html文件
- 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