路由设置:

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import home from '@/components/home/home'


Vue.use(Router)

export default new Router({
  routes: [{
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    //我的
    {
      path: '/home',
      name: 'home',
      component: home
    }
  ]
})

 

1.

<router-link :to="{name:'home',params:{id:'1'}}">
      <div>跳转</div>
</router-link>



<router-link :to="/home?id=1">
      <div>跳转</div>
</router-link>

2.

<h2 @click="fun()">到我的</h2>

//js
fun(){
    //this.$router.push({ path: "/home", params: { id: "1" } });
    //设置了path跳转的话 parmas不生效
    //this.$router.push({ path: "/home", query: { id: "1" } });
    //this.$router.push({ name:'home', params: { id: "1" } });
    //this.$router.push({ path: '/home?id=' + 1});
  }

 

 

接收参数:

created() {

console.log(this.$route.params.id)
console.log(this.$route.query.id)

},

 

that.$router.go(-1);

  1. this.$router.replace() (用法同上,push)
  2. this.$router.go(n) ()
Logo

前往低代码交流专区

更多推荐