先上代碼:html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
</div>
</body>
</html>
複製代碼
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)//這一句很容易忽略
import login from './login.vue'
import account from './main/account.vue'
import list from './main/list.vue'
let router = new VueRouter({
routes:[
{path:'/account',component:account},
{path:'/list',component:list}
]
})
let vm = new Vue({
el:'#app',
data:{
},
router,
render:c=>c(login)
})
複製代碼
<template>
<div>
<h1>app組件</h1>
<router-link to='/account'>account</router-link>
<router-link to='/list'>list</router-link>
<router-view></router-view>
</div>
</template>
<script>
</script>
<style>
</style>
複製代碼
<template>
<div>
<p>註冊組件regiest</p>
</div>
</template>
<script>
</script>
<style>
</style>
複製代碼
<template>
<div>
<p>列表goodslist</p>
</div>
</template>
<script>
</script>
<style>
</style>
複製代碼