2019/07/13 15:01
查詢字符串
在router-link 的to后加?dcm=22
後臺用:$route.query.dcm=22;
params 傳參需要修改路由規則
路由传参案例:
<html>
<head>
<link rel="stylesheet" href="../../lib/animate.css">
<style>
.right{
border: 1px solid #e6e6e6;
}
.my{
color:red;
}
</style>
</head>
<body>
<div id="app">
<div class="left">
<router-link to="/one?i=1">one</router-link>
<router-link to="/two/1/2">two</router-link>
</div>
<div class="right">
<transition enter-active-class="animated bounceIn" leave-active-class="animated bounceOut" mode='out-in'>
<router-view ></router-view>
</transition>
</div>
</div>
</body>
<script src="../../lib/vue-2.4.0.js"></script>
<script src="../../lib/vue-router-3.0.1.js"></script>
<script>
var one={
template:`<h2>one</h2>`
}
var two={
template:`<h2>two</h2>`
}
const router=new VueRouter({//只能定义一个地址
routes:[
{path:'/one',component:one},
{path:'/two/:id/:name',component:two},
{path:"/",redirect:'/one'}
],
linkActiveClass:'my'
})
var vue=new Vue({
el:"#app",
router:router,
})
</script>
</html>