vue 路由配置
阿新 • • 發佈:2018-05-03
nbsp params ID his 這一 one 參數 接收參數 路由配置 ,
1.不帶參數的路由配置 及 跳轉
//路由配置:
{
name: "a", path: "/a", component: a } 頁面跳轉: this.$router.push(‘/a‘); this.$router.push({path:‘/a‘}); this.$router.push({name:‘a‘}) 2.帶參數的路由配置及頁面跳轉 和 接收參數//路由配置:
{
name: "a", path: "/a/:userid", component: a } //頁面跳轉: this.$router.push({name:‘a‘,params:{userid:123}}); 接收: this.$route.params.userid this.$router.push({path:‘/a‘,query:{userid:123}}) 接收: this.$route.query.userid this.$router.push({path:‘/a‘,params{userid:123}}) 錯誤,如果提供了path
params
會被忽略
this.$router.push({path:‘/a/123‘}); 接收: this.$route.params.userid
this.$router.push({path:‘/a?userid=123‘}) 接收:this.$route.query.userid ----- 這一項的路由配置 path:‘/a‘ ,不用帶參數
vue 路由配置