vue中通过路由传参

3 篇文章 0 订阅

表格默认选中事件失效:

方法:
setCurrent(row) {
   this.$refs.singleTable.setCurrentRow(row);
 },
在
created() {
    this.initDeviceList();
    this.initLeftTable();
}的方法 initLeftTable中需要写$nextTick,否则不生效
this.$nextTick(function(){
            // 如果不写在$nextTick中的话不默认选中第一行
this.scoreParent = this.leftTableList[0].evaluatConfigInfo ? JSON.parse(this.leftTableList[0].evaluatConfigInfo) : null;
this.setCurrent(this.leftTableList[0]);//每次更新了数据,触发这个函数即可。
this.$router.push({name: 'corroseIndex',query: { evaluatId: this.leftRowData.evaluatId, loopId:this.leftRowData.loopId }});
})

路由传参方法

handleClick(tab, event) {
 if (tab.name === 'corroseIndex') {
   this.$router.push({name: 'corroseIndex',query: { evaluatId: this.leftRowData.evaluatId, loopId:this.leftRowData.loopId }});
 } else if (tab.name === 'runSituation') {
   this.$router.push({name: 'runSituation',query: { evaluatId: this.leftRowData.evaluatId, loopId:this.leftRowData.loopId }});
 } else if (tab.name === 'selfAbility') {
   this.$router.push({name: 'corroseManage'});
 }
},
第三个tab是以组件的形式引入的,所以需要在点击的时候将路由切换到父级,否则会出现tab1的内容和组件一起渲染

在子页面中获取路由的参数

watch: {
    '$route': {
        handler: function(){
            this.parentEvaluatId = this.$route.query.evaluatId;
            this.parentLoopId = this.$route.query.loopId;
            this.initStandardTableList();
            this.initIndexsTableList();
        }
    }
},
通过watch来监听路由的变化,在子页面取路由参数,切记是this.$route,而不是this.$router
同时:如果不监听路由参数的变化,做页面重新渲染的话,当点击左侧表格的时候路由参数虽然变化,但是没法重新渲染页面

数组A中删除数组B中的相同的数据,重新组装数组

for (let i = 0; i < tableList.length; i++) {
   tableList.index = i;
  for(let j = 0; j < this.standardMediumCode.length;j++){
    if(tableList[tableList.index].mediumCode === this.standardMediumCode[j]){
        tableList.splice(tableList.index, 1);
        i = -1;
    }
  }
  // for (let itemCode of this.standardMediumCode) {
  //   if (tableList[i].mediumCode === itemCode) {
  //     tableList.splice(i, 1);
  //   }
  // }
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值