<!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>
<script src="vue1026.js"></script>
<script src="vue-router1.0.min.js"></script>
</head>
<body>
<div id="app">
<!-- {path} 是跳转路径 -->
<a v-link='{path:"/login"}'>登录</a>
<a v-link='{path:"/register"}'>注册</a>
<!-- 组件显示的位置 -->
<router-view></router-view>
</div>
<script>
//定义根组件
var app = Vue.extend({});
//定义组件
var register = Vue.extend({
template:'<h2>注册</h2>'
})
var login = Vue.extend({
template:'<h2>登录</h2>'
})
//实例化vuerouter对象
var vuerouter =new VueRouter();
//map是一个对象 路由规则
vuerouter.map({
'login':{
component:login
},
'register':{
component:register
}
});
//生效vuerouter
vuerouter.start(app,'#app');
//默认跳转到登录组件显示
vuerouter.redirect({'/':'/login'});
var vm =new Vue({
el:'#app',
})
</script>
</body>
</html>