zoukankan      html  css  js  c++  java
  • 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)
    
  • 相关阅读:
    如何制作静、动态库
    各种时间函数的恩与怨
    一文看懂Vim操作
    如何避免内存泄漏
    和leon一起学Vim
    shell的输入输出重定向
    和Leon一起从头学Git(六)
    和leon一起从头学Git(五)
    深入理解Linux高端内存
    和Leon一起从头学Git(四)
  • 原文地址:https://www.cnblogs.com/wangyingblock/p/13214806.html
Copyright © 2011-2022 走看看