1、项目结构
2、定义组件
组件1 Login.vue
<template>
<form>
账号:<input type="text">
密码: <input type="text" >
</form>
</template>
<script>
export default {
name: "login"
}
</script>
<style scoped>
</style>
组件2 Main.vue
<template>
<h1>这里是主界面</h1>
</template>
<script>
export default {
name: "Main"
}
</script>
<style scoped>
</style>
3、定义路由
import Vue from 'vue'
import Router from 'vue-router'
import Main from '../components/Main'
import Login from '../components/Login'
Vue.use(Router)
export default new Router({
routes: [
{
path:'/main',
component:Main
},
{
path:'/login',
component:Login
}
]
})
4、定义首页
<template>
<div id="app">
<router-link to="/login">login</router-link>
<router-link to="/main">main</router-link>
<h1>大家好</h1>
<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>