<!-- query传参,对象中两个属性,跳转地址和传递参数 -->
<router-link :to="{path:'/mine',query:{course:103}}" tag='span'>去个人中心</router-link>
完整代码展示:
<!DOCTYPE html>
<html>
<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></title>
<script src="https:///npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<style>
.router-link-active {
color: red;
font-size: 30px;
}
</style>
</head>
<body>
<div id='app'>
<router-link to='/index' tag='span'>去首页</router-link>
<!-- query传参,对象中两个属性,跳转地址和传递参数,传递参数为course=103 -->
<router-link :to="{path:'/mine',query:{course:103}}" tag='span'>去个人中心</router-link>
<!-- 4、展示位置 -->
<router-view></router-view>
</div>
<!-- 声明两个组件 -->
<!-- index首页组件 -->
<template id="index">
<div>
<div>首页</div>
</div>
</template>
<!-- mine个人中心组件 -->
<template id="mine">
<div>
<div>个人中心</div>
</div>
</template>
<script>
// 创建路由实例
// 创建index路由实例
let index = {
template: '#index',
}
// 创建mine路由实例
let mine = {
template: '#mine',
}
// 1、创建路由实例
const router = new VueRouter({
// 2、创建映射关系
routes: [
{
path: '/',
// 路由重定向
redirect: '/index'
},
{
path: '/index',
component: index
},
{
path: '/mine',
component: mine
}
]
})
const vm = new Vue({
el: '#app',
data: {
},
// 3、建立联系,将路由挂载在vue实例上
// router:router,
// 简写
router,
methods: {
},
})
</script>
</body>
</html>
结果展示:

















