验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

vue怎么使用router-view调用页面

阅读:1136 来源:乙速云 作者:代码code

vue怎么使用router-view调用页面

使用router-view调用页面

在项目中,需要在其中一个页面,调用很多其他页面的表单,所以使用router来实现页面的调用。

vue-router有传递参数的两种方式,get和post。

1.get方式

页面跳转

this.$router.push({path:'/xxx',query:{id:1}});//类似get传参,通过URL传递参数

新页面接收参数

this.$route.query.id

2.post方式

页面跳转

 //由于动态路由也是传递params的,所以在 this.$router.push() 方法中 path不能和params一起使用
 //否则params将无效。
 //需要用name来指定页面。
 this.$router.push({name:'page2',params:{id:1}});//类似post传参

新页面接收参数

this.$route.params.id

注意:在页面进行刷新的时候经常会遇到参数变了,但是新页面接受的参数没有变化。这种问题可以通过加watch解决。

watch: {
      '$route'(to, from){
        //在这里重新刷新一下
        this.getParams();
      }
    }

实例

首先,我们的页面是wfqlc.vue(我的申请),被调用的页面为pjzydgl.vue(票据准印单管理)。

1.在router的index.js文件里,给我的申请页面加children。

vue怎么使用router-view调用页面

2.在需要跳转的地方添加router-view。


    
        
          
        
    

3.在我的申请wfqlc.vue页面,把请求发送出去。

// 附加单据
    getAdditionalDocument (row) {
      this.fjdjModal = true
      this.$router.push({
        // path: `/wfqlcfjdj/${row.webUnitUrl}`,
        path: `/wfqlcfjdj/pjzydgl`,
        query: {
          // businessIndex: row.businessId
          businessIndex: '6883a5c4-b706-424e-ba88-4acc83eded2f'
        }
      })
    },

4.请求会拼在地址栏发送过去

vue怎么使用router-view调用页面

path传的参数跳转到了对应的页面,businessIndex获取到了对应的值。

5.跳转到票据准印单管理pjzydgl.vue页面。

mounted () {
    if (this.$route.query.businessIndex) {
      this.tzdetail(this.$route.query)
    }
  }

6.根据 businessIndex获取到对应的值。

methods {
  tzdetail (data) {
    this.detail(data.businessIndex, 'detail')
  },
  detail (row) {
    const url = `${window.zvconfig.url.pjsyDetail}?id=${row}`
    this.$axios.get(url).then(res => {
      if (res.data.status === '00000') {
        this.detailForm = res.data.data
        this.childTableData = res.data.data.detailList
      } else {
        this.$Message.error(res.data.msg)
      }
    })
  },
// 关闭弹窗回到我的申请页面
  cancelModal () {
    if (this.$route.path.indexOf('/wfqlcfjdj/') > -1) {
      this.$router.push({
        path: '/wfqlc'
      })
    }
  },
}
分享到:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>