<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script src='../../lib/vue-2.4.0.js'></script>
<script src='../../vue-router-3.0.1.js'></script>
<style>
.router-link-active{
background-color: green;
font-size: larger;
color: aliceblue
}
.v-enter,
.v-leave-to {
opacity: 0;
transform: translateX(150px);
}
.v-enter-active,
.v-leave-active {
transition: all 0.5s ease;
}
</style>
</head>
<body>
<div id="pp">
<!-- 创建两个button, 并通过href 找到相应组建的路由 -->
<router-link to='/login' tag="span">登录</router-link>
<router-link to='/registe' tag="span">注册</router-link>
<!-- 用于显示路由组建 -->
<transition mode='out-in'>
<router-view></router-view>
</transition>
</div>
<script>
// 创建两个组建模板对象,让路由能找到并显示这个组件
var tmp1={
template:'<h1>登录</h1>',
}
var tmp2={
template:'<h1>注册</h1>',
}
// 创建路由对象,并设置路由的参数 ,第一个是path, 第二个是 要匹配的组建
var routerObj=new VueRouter({
routes:[
{path:'/',redirect:'/login'},
{path:'/login',component:tmp1},
{path:'/registe',component:tmp2}
],
myactive: 'router-link-active',
})
new Vue({
el:'#pp',
data:{
},
methods:{
},
// 让路由对象 和vue 实例 绑定关系, 用于监听。
router: routerObj,
})
</script>
</body>
</html>
前端应用_Vue_设置router 切换路由动画
最新推荐文章于 2023-05-05 17:42:17 发布