vue 点击一条消息跳转相应的页面且对应相应的大模块和办理状态

需求:点击一条消息跳转相应的页面且对应相应的大模块和办理状态为选中状态

问题描述:点击一条消息后将需要改变的参数拼接到url地址中跳转到A页面,当将参数赋值给办理状态时页面办理状态不改变

解决:使用watch监听属性监听url变化 && 给url加时间戳(防止缓存url没有改变watch监听不到)

消息列表中点击事件中:

handleRead (item, index) {
        let status = item.status
        let business_code = item.business_code
        let getTimestamp=new Date().getTime(); //加时间戳防止url没有改变watch监听不到
        this.$router.push({
          path:`/regulation/xzsp?status=${status}&business_code=${business_code}+${getTimestamp}`
        })
        this.$emit('handle-hide')
}

A页面中:

watch:{
      $route(to, from) { // watch属性监听路由变化
        this.activeNameFn()
      }
},
methods:{
      activeNameFn(){
        if(this.$route.query.status!=undefined){
          this.activeName = this.$route.query.status
          this.business_code = this.$route.query.business_code
          console.log(this.activeName,'router')
        } else {
          this.activeName = 'DJ'
          console.log(this.activeName,'11')
        }
        console.log(this.activeName)
      },
}
原文地址:https://www.cnblogs.com/duhui/p/13085210.html