vue-router

初始化
new Router({
  routes, // 路由配置
  mode: "history",
  fallback:true,
  linkExactActiveClass: "exact-active",
  linkActiveClass: "active",
  scrollBehavior(to,from,savedPosition){
  	if(savedPosition){
		return savedPosition
	}else {
		return {x:0,y:0}
	}
  }
})
路由配置
const routes = [
	{
		path:'/',
		redirect:'/home'
	},
	{
		path:'/home',
		component: HomeCmp,
		name:'home',
		meta:{
			title:'首页',
			description:'这是首页'
		},
		children:[
			{
			 	path:'test',
			 	component:TestCmp,
			 	name:'test',
			}
		]
	}
]

<router-link to="/home">home</router-link>
<router-link :to="{name:'home'}">home</router-link>

<router-view></router-view>
// 路由过渡动画
.fade-enter-active,.fade-leave-active{
	transition:opacity 0.5s;
}
.fade-enter,.fade-leave-to{
	opacity:0
}
<transition name="fade">
	<router-view />
</transition>
路由传参
[
	{
		path:'/app/:id',
		component:AppCmp,
		name:'app'
	},
	{
		path:'/app2/:id2',
		component:App2Cmp,
		name:'app2',
		props:true,
	}

]
let _id = this.$route.params.id // 获取参数
// 注册props
props:['id2']
// 获取id
let _id2 = this.props.id2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值