vue 页面跳转传值

<router-link :to="{path:'/test',query: {userid: id}}">跳转</router-link>

使用query传递参数,路由必须使用path引入; 使用params传递参数,路由必须使用name引入

取值方式:this.$route.query.key this.$route. params.key

二、$router方式跳转

1、query

this.$router.path({
  path: '/detail',
  query: {
    name: 'admin',
    code: 10021
  }
})

取值方式:this.$route.query.name
注意: 页面刷新时,传的值会没有

2、params

this.$router.path({
  name: 'detail',
  params: {
    code: 10021
  }
})

取值方式:this.$route. params. code

3、url拼接

this.$router.push({
        path: `/approveManage/approveDetail/${item.id}`
})

对应路由:path: '/configManage/addReleaseConfig/:id'
取值方式: this.$route.params.id

三、LocalStorage存值

将需要传递的值保存值本地,需要的时候再去取

// 保存userid至内存
var userID = 1;
localStorage.setItem('storeID',JSON.stringify(userID))

取值方式:

this.userID= JSON.parse(localStorage.userID)
posted @ 2020-06-30 17:08  yingzi__block  阅读(1225)  评论(0编辑  收藏  举报